You are on page 1of 8

Smit thummar 19BCH060

Process Modeling and Optimization Lab

Labwork 5

Submitted in partial fulfillment of the requirement for

the Process Modeling and Optimization laboratory

BY

SMIT THUMMAR (19BCH060)

Semester : 7

Branch: Chemical Engineering

Submitted to: Dr. Subhankar Roy

Date of Submission: 17th October, 2022

SCHOOL OF TECHNOLOGY

PANDIT DEENDAYAL ENERGY UNIVERSITY

GANDHINAGAR-382007, GUJARAT, INDIA


Smit thummar 19BCH060

Theory:

What is Newton-Raphson Method?


The Newton-Raphson method (also known as Newton's method) is a way to quickly find a good
approximation for the root of a real-valued function f(x)=0. It uses the idea that a continuous and
differentiable function can be approximated by a straight line tangent to it.
How it works:
Suppose we need to find the root of a differentiable function f(x), and we know the root we are
looking for is near the point x = x0. Then Newton's method tells us that a better approximation for
the root is
𝑓 (𝑥 0)
𝑥1 = 𝑥0 −
𝑓′(𝑥 )0

This process may be repeated as many times as necessary to get the desired accuracy. In general, for
any x-value xn, the next value is given by
𝑓(𝑥𝑛)
𝑥𝑛+1 = 𝑥𝑛 −
𝑓′(𝑥 ) 𝑛

Geometric Representation

We draw a tangent line to the graph of f(x) at the point x = xn. This line has slope f'(xn) and goes
through the point (xn, f(xn)). Therefore, it has the equation y=f’(xn)(x- xn) + f(xn). Now, we find the
root of this tangent line by setting y = 0 and x= xn +1 for our new approximation. Solving this
equation gives us our new approximation, which is
𝑓(𝑥𝑛)
𝑥𝑛+1 = 𝑥𝑛 −
𝑓′(𝑥 ) 𝑛

Optimization using Newton


Raphson:
𝑓′(𝑥𝑛)
𝑥𝑛+1 = 𝑥𝑛 −
𝑓′′(𝑥 )𝑛

2
Smit thummar 19BCH060

Problem statement 1(a):

F(x) = ex-x3.

Use Newton Raphson method to find the root of this function using two initial guess values (i) x0=0
and (ii) x0=1.5. Write your observations

Code:
1) Take initial value x0=0

clc
clear all
x1=0; %Initial guess value
x(1)=x1;
for i=1:15
y(i)=exp(x(i))-(x(i)^3);
yder(i)=exp(x(i))-3*(x(i)^2);
x(i+1)=x(i)-(y(i)/yder(i));
end
x

x =

Columns 1 through 17

0 -1.0000 -0.4803 9.4420 8.4885 7.5737 6.7216 5.9636 5.3370


4.8807 4.6241 4.5437 4.5365 4.5364 4.5364 4.5364

2). Take initial value x0=1.5


Code:-
clc
clear all
x1=1.5; %Initial guess value
x(1)=x1;
for i=1:5
y(i)=exp(x(i))-(x(i)^3);
yder(i)=exp(x(i))-3*(x(i)^2);
x(i+1)=x(i)-(y(i)/yder(i));
end
x
x =

1.5000 1.9879 1.8659 1.8572 1.8572 1.8572

Results:

Initial guess value (x0) Root No. of iterations


0 4.5364 14
1.5 1.8572 4

3
Smit thummar 19BCH060

It was observed that as we change the value of the initial value the root obtained was changed so it
was the limitation. To find all the roots using matlab we should have curve of the function so that we
can guess initial values for root finding as we have to do more initial guess to find all the solution.
Also it was found that is root is near to the guess value than less iterations are required.

4
Smit thummar 19BCH060

Problem statement 1(b):

F(x) = ex-x3.
Use Newton Raphson method to find the optimum of this function using three initial guess values (i)
x0=0 and (ii) x0=1 and (iii) x0=10. Write your observations.

Code:
1. x0=0
clc
clear all
x1=0;%Initial guess value
x(1)=x1;
for i=1:6
y(i)=exp(x(i))-(x(i)^3);
yder(i)=exp(x(i))-3*(x(i)^2);
y2der(i)=exp(x(i))-(6*x(i));
x(i+1)=x(i)-(yder(i)/y2der(i));
error(i)=(x(i+1)-x(i))/x(i)
end
x

x = 0 -1.0000 -0.5867 -0.4698 -0.4591 -0.4590 -0.4590

2. x0=1
code:
clc
clear all
x1=1;%Initial guess value
x(1)=x1;
for i=1:5
y(i)=exp(x(i))-(x(i)^3);
yder(i)=exp(x(i))-3*(x(i)^2);
y2der(i)=exp(x(i))-(6*x(i));
x(i+1)=x(i)-(yder(i)/y2der(i));
error(i)=(x(i+1)-x(i))/x(i)
end
x

x =

1.0000 0.9142 0.9100 0.9100 0.9100 0.9100

3. x0=1
code:
clc
clear all
x1=10;%Initial guess value
x(1)=x1;
for i=1:15
y(i)=exp(x(i))-(x(i)^3);
yder(i)=exp(x(i))-3*(x(i)^2);
y2der(i)=exp(x(i))-(6*x(i));
x(i+1)=x(i)-(yder(i)/y2der(i));
error(i)=(x(i+1)-x(i))/x(i)
end
x
5
Smit thummar 19BCH060

x =

Columns 1 through 13

10.0000 9.0109 8.0342 7.0821 6.1762 5.3504 4.6515 4.1331 3.8370


3.7421 3.7332 3.7331 3.7331

Columns 14 through 16

3.7331 3.7331 3.7331

Results:

Initial guess value (x0) Optimum Value No. of iterations


0 -0.4590 7
1 0.9100 4
10 3.7331 15

It was observed that as we change the value of the initial value the optimum value obtained was
changed. To find optimum value using matlab we should have curve of the function so that we can
guess initial values for optimum value finding as we have to do more initial guess to find optimum
value as we are unaware that where optima of this function lies.

6
Smit thummar 19BCH060

Problem statement 1(c):

F(x) = ex-x3.

Use bisection method to find the optimum of this function in the intervals of (i) [2 5] and (ii) [-2 5].
Write your observations.

Theory:

Optimization using Bisection Method:


In, bisection method we initially have been provided with[a,b]. Once, [a,b] is obtained, we need
to find c, which is given by:
a+b
c=
2
Now, we need to find f’(a), f’(b) and f’(c). Once, the values of these terms are obtained, we need to
take either the product of f’(a)*f’(c) or f’(b)*f’(c). Once this is done, check if the product
f’(a)*f’(c)<0, then b=c, else a=c. This will give us new value of c and the procedure is repeated in a
continuous fashion until the error tolerance is found in the given range.

1. For range [2 5]
Code:
clc
clear all
a=2; b=5; %Bound
for i=1:20
c=(b+a)/2;
ydera=exp(a)-3*((a)^2)
yderb=exp(b)-3*((b)^2)
yderc=exp(c)-3*((c)^2)
if ydera*yderc<0
b=c
else
a=c
end
updatedc(i)=c;
end
updatedc

updatedc =

Columns 1 through 13

3.5000 4.2500 3.8750 3.6875 3.7812 3.7344 3.7109 3.7227 3.7285


3.7314 3.7329 3.7336 3.7333

Columns 14 through 20

3.7331 3.7330 3.7330 3.7331 3.7331 3.7331 3.7331

7
Smit thummar 19BCH060

2. For range [-2 5]


Code:
clc
clear all
a=-2; b=5; %Bound
for i=1:20
c=(b+a)/2;
ydera=exp(a)-3*((a)^2)
yderb=exp(b)-3*((b)^2)
yderc=exp(c)-3*((c)^2)
if ydera*yderc<0
b=c
else
a=c
end
updatedc(i)=c;
end
updatedc

updatedc =

Columns 1 through 13

1.5000 3.2500 4.1250 3.6875 3.9062 3.7969 3.7422 3.7148 3.7285


3.7354 3.7319 3.7336 3.7328

Columns 14 through 20

3.7332 3.7330 3.7331 3.7331 3.7331 3.7331 3.7331

Results:

Interval Optimum Value No. of iterations


[2,5] 3.7331 18
[-2,5] 3.7331 17

It was observed that as we change the value of the bound the optimum value obtained was remain
unchanged as the optimum value lies in that bound. If we change bound to [2 3] than we will get
optima 3 as opima of the function is not included in our guess. To find optimum values using matlab
we should have curve of the function so that we can guess bound for finding optima.

You might also like