NEOM UNIT-1 Sept-23
NEOM UNIT-1 Sept-23
1
9/3/2023
What is Optimization ?
2
9/3/2023
Objective function:
• It is the mathematical function which expresses the main aim
of the optimization model to be either minimized or
maximized subject to certain constraints.
For example, in a manufacturing process, the aim may be
to maximize the profit or minimize the cost.
• Constraints
A set of constraints are those which allow the unknowns to take on
certain values but exclude others.
For example, one cannot spend negative amount of time on
any activity in manufacturing process, so one constraint is
"time" variable that is to be non-negative.
3
9/3/2023
Mathematical perceptions:
• Existence of constraints: an optimization problem can be classified as a constrained or
an unconstrained one.
• Nature of the equations: Linear, Quadratic, Polynomial, Non-linear depending upon the
nature of the objective functions and the constraints. The nature of the involved functions
dictates the type of solution procedure.
• Admissible values of the design variables: Depending upon the values permitted for the
design variables, optimization problems can be classified as integer or real valued, and
deterministic or stochastic.
4
9/3/2023
Concept
Global optimal point (x**): If there exist no point in the entire search
space which is
better than the point x**; if no point in the entire search space has a
function value smaller than f(x**).
Inflection Point (x*): If the function value f(x*) increases locally as
x*increases, and decreases locally as x*reduces or, if the function
value decreases locally as x* increases and increases locally as x*
decreases., OR
It is a point where the function changes from being
concave (concave downward) to convex (concave upward), or vice
versa.
5
9/3/2023
Stationary point :
A stationary point of a differentiable function of one variable is a point on the
graph of the function where the function's derivative is zero.
6
9/3/2023
Maximum at
Minimum at boundary
boundary
Maximum in Maximum at
interior boundary
Maximum at
boundary Minimum in
Minimum in Minimum at interior
interior boundary
This means that any procedure attempting to minimize with a nonlinear objective
function needs to have two components: one that considers the boundaries (including
the corners) and one that checks the interior
7
9/3/2023
This type problem is called a constrained optimization problem. The set of values of
X that satisfy the equation gi(X) <=0 forms a boundary surface in the design space
called a constraint surface and the other in which gi(X) > 0 is called infeasible region.
0
8
9/3/2023
9
9/3/2023
Types of
minima
Saddle Points
A saddle point is a point on a function that is a stationary
point but not a local extremum. It is a point at which a
function has partial derivatives equal to zero, but at which the
function has neither a maximum nor a minimum value.
10
9/3/2023
Maxima, Minima (call them the relative maxima and minima or more generally the
relative extrema) and Inflection points :
11
9/3/2023
12
9/3/2023
BISECTION METHOD
Bisection Method
To find a root, repeatedly halve the interval [a, b], keeping the half for which
f(x) changes sign i.e. to check sign of f(a) and f(b) and decide a new
interval such that f(a)f(b) < 0 .
This procedure is guaranteed to converge to a root.
Let c1 = (a+b)/2 is the midpoint of the initial interval, and cn is the midpoint of
the interval in the nth step, then the difference between cn and a solution c is
bounded by
13
9/3/2023
14
9/3/2023
Coding
Prob: Find the largest root of f(x) = x3 − x − 1 = 0
accurate to within ε= 0.001.
After 9 iterations the value of f(c) is less than our defined tolerance (0.0072393 < 0.01). This means that the value that approximates
best the root of the function f is the last value of c = 3.1611328.
15
9/3/2023
A better approximation is obtained if we find the point (c, 0) where the secant line L
(secant line intersects the curve at a minimum of two distinct points) joining the
points (a, f (a)) and (b, f (b)) crosses the x-axis as shown.
where the points (a, f (a)) and (b, f (b)) are used,
16
9/3/2023
…………….(5)
The regula-falsi
method…Algorithm
1.Determine the points a and b such that a < b and f(a) * f(b) < 0.
17
9/3/2023
18
9/3/2023
Coding
Prob: Find the largest root of f(x) = x3 − 2x − 5 = 0
end
answer=p
plot(error)
grid on;
title ('Plot of Error');
xlabel('iterations');
ylabel('error');
fprintf('\n Therefore,x2=%.4f \n Here,
f(x2)= %.4f', x2(i),f(x2(i)))
19
9/3/2023
20
9/3/2023
NR-Formula
21
9/3/2023
𝑓(𝑥k+Δ𝑥)=𝑓(𝑥k)+𝑓′(𝑥k)Δ𝑥+1/2! 𝑓′′(𝑥k)Δ𝑥2+⋯
22
9/3/2023
N-R : Drawbacks
DRAWBACKS of NR:
• The soln may diverge near a point of inflectiona point (at which a
change in the direction of curvature occurs)
• With near zero slope , the solution may diverge or reach a different
root
• Slow convergence
N-R : PROBLEMS
• f(x) = x−2+ln(x) has a root near x = 1.5. Use the Newton-Raphson formula
to obtain a better estimate
23
9/3/2023
N-R
Newton’s method is an iterative method for
solving nonlinear systems
%The following script, to be saved under the name ‘newton.m’, to implements Newton’s
%method, to compute the root of the equation x3 − 3x +1 = 0.
%format
%short;
• clc;
• syms x;
• display (’Newton’’s method is an iterative method for solving
• nonlinear systems’);
• f = input(’Enter the function f(x)=’);
• x0 = input(’Enter the initial estimate of the solution: ’);
• n = input(’Enter the maximum number of iterations: ’);
• e = input(’Enter the margin of error: ’);
• i = 0;
• while (i<n)
• df = diff(f,x);
• dfx0 = subs(df,x,x0);
• fx0 = subs(f,x,x0);
• x1 = x0 - (fx0/dfx0);
• dx = x1 - x0;
• if abs(dx)/abs(x0)<=e
• fprintf(’The solution is = %i\n’,x1);
• fprintf(’The number of iterations required was = %i\n’,i);
• break
• end
• i = i+1;
• x0=x1;
• end
• if abs(dx)/abs(x0) >e
• fprintf(’Convergence was not achieved in n iterations ’);
• end
N-R-2
Input:
• Enter the function f(x)=x^3-3*x+1
• Enter the initial estimate of the solution: 0
• Enter the maximum number of iterations: 100
• Enter the margin of error: 0.001
Output:
• The solution is = 3.472964e-001
• The number of iterations required was = 2
• Therefore, the solution computed by this script is x = 0.3473.
24
9/3/2023
N-Optimization
N-R Coding
25
9/3/2023
N-R Coding
% N-R Solution for f(x)=x-cos(x)
clc
i=1;
p0=0.5*pi;
N=40;
error=0.0001;
syms x
f=x-2*cos(x)+1;
df=diff(f);
while i<=N
p=p0-(subs(f,p0)/subs (df,p0))
if abs ((p0-p)/p0)< error
fprintf('solution is %f \n',p)
disp(i)
return
end
i=i+1
p0=p
end
fprintf('Diverge after %d itrations at precision of %d \n',N,error)
N-R Coding
26
9/3/2023
• The diff equations to be solved in power system stability analysis are nonlinear
ordinary differential equations with known initial values:
x - independent variable.
Euler Method
27
9/3/2023
28
9/3/2023
where,
where,
k1= (slope at the beginning of step size) x h
k2= (first approximation to slope at midstep) x h
k3= (second approximation to slope at midstep) x h
k4= (slop at the end of step) x h
29
9/3/2023
Solve
y’ = f (t, y) = y − t2 + 1
y(0) = 0.5
%function f=f(t,y)
%f=y-t.^2+1;
%Main file
clc
h=0.25; % step size
t(1)=0;% zero time
x(1)=0.5;% initial condition
y_true=zeros(1,8)
for i=1:8
k1=h*f(t(i),x(i));
k2=h*f(t(i)+h/2,x(i)+k1/2);
k3=h*f(t(i)+h/2,x(i)+k2/2);
k4=h*f(t(i)+h,x(i)+k3);
x(i+1)=x(i)+(k1+2*k2+2*k3+k4)/6;
t(i+1)=t(i)+h;
y_true=t.^2+2*t+1.0-0.5*exp(t)
end
%t=[0:h:2]
%y_true=t.^2+2*t+1.0-0.5*exp(t)
plot(t,x,'k-',t,y_true,'m+')
xlabel('t')
ylabel('x')
legend('Runge Kutta 4th Order:True Soln vs. RK soln.')
30
9/3/2023
dVc
i C
dt
di
L iR Vc Vin
dt
d 2V dV
or , LC 2c RC c Vc Vin
dt dt
1
Vc 2nVc n 2Vc Vin
LC
1
ω n= Where,
LC
R C 𝝎n=Natural frequency
ξ= ξ= Damping co-efficient
2 L
31
9/3/2023
CODING:
% Runge Kutta 4 Solution .
% Let’s get the transient analysis of circuit for an
overdamped system.
% R=300,200,100 L= 10mH,C=1uF and Vin=10V & W0
%=1000
% I(0)=0,Vc(0)=0%
clc
t=0; T=0.001; h=0.0001; x1=0; x2=0; i=1;
%c=0.000001;l= 0.01; r=300; Vin=10;
%c=0.000001;l= 0.01; r=200; Vin=10;
c=0.000001;l= 0.01; r=100; Vin=10;%underdamped
f=@(t,x1,x2) x2/c;
g= @(t,x1,x2)((Vin-x1-r*x2)/l);
fprintf('time\t\tvoltage\tcurrent\n');
for t=0:h:T
fprintf('%f\t%f\t%f\n',t,x1,x2);
32
9/3/2023
33
9/3/2023
Over damped
THANKS
34