SlideShare a Scribd company logo
Islamic Azad University
Qazvin Branch
Faculty of Industrial and Mechanics , Department of Mechanical
Engineering
Subject
Compare Some Algorithms for Solving Nonlinear Equation
Thesis Advisor
Dr.Marufi
By
Parham Sagharichi Ha
Assignment of Numerical Analysis Parham Sagharichi Ha
parhamsagharchi@gmail.com 1
Problem
The speed v of a Saturn V rocket in vertical flight near the surface of earth can
be approximated by
𝑣 = 𝑢 ln
𝑀0
𝑀0 − 𝑚̇ 𝑡
− 𝑔𝑡
𝑢 = 2510
𝑚
𝑠
= 𝑣𝑒𝑙𝑜𝑐𝑖𝑡𝑦 𝑜𝑓 𝑒𝑥ℎ𝑎𝑢𝑠𝑡 𝑟𝑒𝑙𝑎𝑡𝑖𝑣𝑒 𝑡𝑜 𝑡ℎ𝑒 𝑟𝑜𝑐𝑘𝑒𝑡
𝑀0 = 2.8 ∗ 106
𝑘𝑔 = 𝑚𝑎𝑠𝑠 𝑜𝑓 𝑟𝑜𝑐𝑘𝑒𝑡 𝑎𝑡 𝑙𝑖𝑓𝑡𝑜𝑓𝑓
𝑚̇ = 13.3 ∗ 103
𝑘𝑔
𝑠
= 𝑟𝑎𝑡𝑒 𝑜𝑓 𝑓𝑢𝑒𝑙 𝑐𝑜𝑛𝑠𝑢𝑚𝑝𝑡𝑖𝑜𝑛
𝑔 = 9.81
𝑚
𝑠2
= 𝑔𝑟𝑎𝑣𝑖𝑡𝑎𝑡𝑖𝑜𝑛𝑎𝑙 𝑎𝑐𝑐𝑒𝑙𝑒𝑟𝑎𝑡𝑖𝑜𝑛
𝑡 = 𝑡𝑖𝑚𝑒
Determine the time when the rocket reaches the speed of sound (335 m/s).
Solution
𝑢 𝑙𝑛
𝑀0
𝑀0 − 𝑚̇ 𝑡
− 𝑔𝑡 − 𝑣 = 0
Now we want to determine time in the above equation
Assignment of Numerical Analysis Parham Sagharichi Ha
parhamsagharchi@gmail.com 2
Matlab
1) Bisection Method
Script :
clc
close all
clear all
%%
% Subject : Bisect Algorithm
% Author: Parham Sagharichi Ha Email :
parhamsagharchi@gmail.com
%%
%-------------------S------T------A------R------T------------
-------------%
global tolerance
tolerance = 1e-4; % for example : 1e-4 = 10^-4
u = 2510;
M0 = 2.8*10^6;
mdot = 13.3*10^3;
g = 9.81;
v = 335;
xlower = 0;
xupper = 100;
myfun = @(t)(u.*log(M0./(M0-mdot.*t))-g.*t-v);
[root,iflag] = fbisect(myfun,xlower,xupper);
switch iflag
case -2
disp('Initial range does not only contain one root')
otherwise
disp([' Root = ' num2str(root) ...
' found in ' num2str(iflag) ' iterations'])
end
%---------------F------I------N------I------S------H---------
-------------%
Assignment of Numerical Analysis Parham Sagharichi Ha
parhamsagharchi@gmail.com 3
Function :
function [root,iflag] = fbisect(myfun,a,b)
if a>=b
disp(' attention b>a in [a b] ')
return
end
global tolerance
x = a:0.001:b;
y = feval(myfun,x);
fa = y(1);
fb = y(end);
ymax = max(y);
ymin = min(y);
figure
plot(x,y)
grid on
hold on
plot([a a],[ymin ymax])
plot([b b],[ymin ymax])
iflag = 0;
iterations = 0 ;
while (fa*fb<0) & (b-a)>tolerance
iterations = iterations + 1;
c = (a+b)/2;
fc = feval(myfun,c);
plot([c c],[ymin ymax])
pause
if fa*fc<0
b = c; fb = fc;
elseif fa*fc>0
a = c; fa = fc;
else
iflag = 1;
root = c
return
end
end
switch iterations
case 0
iflag = -2; root = NaN;
otherwise
iflag = iterations; root = c;
end
Assignment of Numerical Analysis Parham Sagharichi Ha
parhamsagharchi@gmail.com 4
Result :
Root = 70.8779 found in 20 iterations
2) Linear Interpolation (False Position) Method :
Script :
clc
close all
clear all
%%
% Subject : False Postion Algorithm
% Author: Parham Sagharichi Ha Email :
parhamsagharchi@gmail.com
%%
%-------------------S------T------A------R------T------------
-------------%
global tolerance
tolerance = 1e-4; % for example : 1e-4 = 10^-4
u = 2510;
M0 = 2.8*10^6;
mdot = 13.3*10^3;
g = 9.81;
v = 335;
xlower = 0;
xupper = 100;
myfun = @(t)(u.*log(M0./(M0-mdot.*t))-g.*t-v);
[root,iflag] = finter(myfun,xlower,xupper);
switch iflag
case -2
disp('Initial range does not only contain one root')
otherwise
disp([' Root = ' num2str(root) ...
' found in ' num2str(iflag) ' iterations'])
end
%---------------F------I------N------I------S------H---------
-------------%
Assignment of Numerical Analysis Parham Sagharichi Ha
parhamsagharchi@gmail.com 5
Function :
function [root,iflag] = finter(myfun,a,b)
if a>=b
disp(' attention b>a in [a b] ')
return
end
global tolerance
x = a:0.001:b;
y = feval(myfun,x);
fa = y(1);
fb = y(end);
ymax = max(y);
ymin = min(y);
figure
plot(x,y)
grid on
hold on
plot([a a],[ymin ymax])
plot([b b],[ymin ymax])
iflag = 0;
iterations = 0 ;
while (fa*fb<0) & (b-a)>tolerance
iterations = iterations + 1;
c = b - (fb)*(a-b)/(fa-fb);
fc = feval(myfun,c);
plot([c c],[ymin ymax])
pause
if fa*fc<0
b = c; fb = fc;
elseif fa*fc>0
a = c; fa = fc;
else
iflag = 1;
root = c
return
end
end
switch iterations
case 0
iflag = -2; root = NaN;
otherwise
Assignment of Numerical Analysis Parham Sagharichi Ha
parhamsagharchi@gmail.com 6
iflag = iterations; root = c;
end
Result :
Root = 70.878 found in 24 iterations
3) Newton-Raphson Method :
Script :
clc
close all
clear all
%%
% Subject : Newton_Raphson Algorithm
% Author: Parham Sagharichi Ha Email :
parhamsagharchi@gmail.com
%%
%-------------------S------T------A------R------T------------
-------------%
format short E
tolerance = 1e-4; % for example : 1e-4 = 10^-4
xlower = 0;
xupper = 100;
xguess = 45;
if (xguess>xupper)||(xlower>xguess)
disp(' error , repate again ')
return
end
xrange = xlower:0.1:xupper;
s = size(xrange);
u = 2510;
M0 = 2.8*10^6;
mdot = 13.3*10^3;
g = 9.81;
v = 335;
syms x
myfun = u.*log(M0./(M0-mdot.*x))-g.*x-v;
Assignment of Numerical Analysis Parham Sagharichi Ha
parhamsagharchi@gmail.com 7
u = 2510;
M0 = 2.8*10^6;
mdot = 13.3*10^3;
g = 9.81;
v = 335;
for i = 1:s(2);
y(i) = double(subs(myfun,[x],[xrange(i)]));
end
fa = y(1);
fb = y(end);
ymax = max(y);
ymin = min(y);
figure
plot(xrange,y)
grid on
hold on
plot([xlower xlower],[ymin ymax])
plot([xupper xupper],[ymin ymax])
plot([xlower xupper],[0 0])
iflag = 0;
iterations = 1 ;
f = double(subs(myfun,[x],xguess));
myfun_prime = jacobian(myfun,x);
fprime = double(subs(myfun_prime,[x],xguess));
xn = xguess;
xnew = xn - f/fprime;
plot([xn xn],[0 f])
pause
plot([xn xnew],[f 0])
while (abs(xnew-xn)>tolerance) & (iterations<30)
iterations = iterations + 1;
xn = xnew;
f = double(subs(myfun,[x],xn));
fprime = double(subs(myfun_prime,[x],xn));
xnew = xn - f/fprime;
root = xnew;
pause
plot([xn xn],[0 f])
pause
plot([xn xnew],[f 0])
end
Assignment of Numerical Analysis Parham Sagharichi Ha
parhamsagharchi@gmail.com 8
switch iterations
case 30
disp(' Not root found ');
otherwise
disp([' Root = ' num2str(root) ...
' found in ' num2str(iterations) ' iterations
'])
end
%---------------F------I------N------I------S------H---------
-------------%
Result :
Root = 70.878 found in 5 iterations
4) Mueller’s Method :
Script :
clc
close all
clear all
%%
% Subject : Mueller’s Algorithm
% Author: Parham Sagharichi Ha Email :
parhamsagharchi@gmail.com
%%
%-------------------S------T------A------R------T------------
-------------%
tolerance = 1e-4; % for example : 1e-4 = 10^-4
u = 2510;
M0 = 2.8*10^6;
mdot = 13.3*10^3;
g = 9.81;
v = 335;
xlower = 0;
xupper = 100;
Assignment of Numerical Analysis Parham Sagharichi Ha
parhamsagharchi@gmail.com 9
xguess = 45;
if (xguess>xupper)||(xlower>xguess)
disp(' error , repate again ')
return
end
myfun = @(t)(u.*log(M0./(M0-mdot.*t))-g.*t-v);
x = [xlower xguess xupper]';%[x2 x0 x1]
xe = xlower:0.1:xupper;
ye = feval(myfun,xe);
ymax = max(ye);
ymin = min(ye);
figure
plot(xe,ye)
grid on
hold on
rline = plot([xlower xlower],[ymin ymax]);
mline = plot([xguess xguess],[ymin ymax]);
fline = plot([xupper xupper],[ymin ymax]);
pause
iterations = 0;
while (true)
iterations = iterations +1;
y = feval(myfun,x);%[f2 f0 f1]
h1 = x(3)-x(2);
h2 = x(2)-x(1);
gamma = h2/h1;
c = y(2);
a = (gamma*y(3)-y(2)*(1+gamma)+y(1))/(gamma*h1^2*(1+gamma));
b = (y(3)-y(2)-a*h1^2)/h1;
if b>0
root = x(2)-(2*c)/(b+sqrt(b^2-4*a*c));
else
root = x(2)-(2*c)/(b-sqrt(b^2-4*a*c));
end
pause
rootline = plot([root root],[ymin ymax]);
if root>x(2)
x = [x(2) root x(3)];
else
x = [x(1) root x(2)];
end
pause
delete(rootline)
delete(rline)
delete(mline)
delete(fline)
Assignment of Numerical Analysis Parham Sagharichi Ha
parhamsagharchi@gmail.com 10
rline = plot([x(1) x(1)],[ymin ymax]);
mline = plot([x(2) x(2)],[ymin ymax]);
fline = plot([x(3) x(3)],[ymin ymax]);
if (abs(feval(myfun,root))<(10^-8))&(iterations<30)
break
end
end
switch iterations
case 30
disp(' Not root found ');
otherwise
disp([' Root = ' num2str(root) ...
' found in ' num2str(iterations) ' iterations
'])
end
Result :
Root = 70.878 found in 5 iterations
5) 𝑥 = 𝑔(𝑥) Method :
𝑢 𝑙𝑛
𝑀0
𝑀0 − 𝑚̇ 𝑡
− 𝑔𝑡 − 𝑣 = 0
First Equation :
𝑡 =
𝑢
𝑔
𝑙𝑛
𝑀0
𝑀0 − 𝑚̇ 𝑡
−
𝑣
𝑔
Second Equation :
𝑡 =
𝑀0
𝑚̇
(
exp (
𝑔𝑡 + 𝑣
𝑢
) − 1
exp (
𝑔𝑡 + 𝑣
𝑢
)
)
Assignment of Numerical Analysis Parham Sagharichi Ha
parhamsagharchi@gmail.com 11
Script :
clc
close all
clear all
%%
% Subject : x=g(x) Algorithm
% Author: Parham Sagharichi Ha Email :
parhamsagharchi@gmail.com
%%
%-------------------S------T------A------R------T------------
-------------%
tolerance = 1e-4; % for example : 1e-4 = 10^-4
u = 2510;
M0 = 2.8*10^6;
mdot = 13.3*10^3;
g = 9.81;
v = 335;
xlower = 0;
xupper = 100;
xguess = 45;
if (xguess>xupper)||(xlower>xguess)
disp(' error , repate again ')
return
end
myfun1 = @(t)((u/g).*log(M0./(M0-mdot.*t))-v/g);
myfun2 = @(t)((M0/mdot).*(exp((g.*t+v)/u)-
1)./exp((g.*t+v)/u));
xold1 = xguess;
xnew1 = feval(myfun1,xold1);
iterations1 = 0;
while (abs(xnew1-xold1)>tolerance)&(iterations1<30)
iterations1 = iterations1 + 1;
xold1 = xnew1;
xnew1 = feval(myfun1,xold1);
Assignment of Numerical Analysis Parham Sagharichi Ha
parhamsagharchi@gmail.com 12
end
root1 = xnew1(end);
switch iterations1
case 30
disp(' Not root found ');
otherwise
disp([' Root1 = ' num2str(root1) ...
' found in ' num2str(iterations1) ' iterations1
'])
end
xold2 = xguess;
xnew2 = feval(myfun2,xold2);
iterations2 = 0;
while (abs(xnew2-xold2)>tolerance)&(iterations2<30)
iterations2 = iterations2 + 1;
xold2 = xnew2;
xnew2 = feval(myfun2,xold2);
end
root2 = xnew2(end)
switch iterations2
case 30
disp(' Not root found ');
otherwise
disp([' Root2 = ' num2str(root2) ...
' found in ' num2str(iterations2) ' iterations2
'])
end
Result :
Not root found
root2 =
7.0878e+01
Root2 = 70.8779 found in 20 iterations2
References
Kiusalaas, J. (2009) Numerical Methods in Engineering with MATLAB®

More Related Content

What's hot

System Of Linear Equations
System Of Linear EquationsSystem Of Linear Equations
System Of Linear Equations
saahil kshatriya
 
Taylor series
Taylor seriesTaylor series
Taylor series
Milan Bhatiya
 
Matrices
Matrices Matrices
Matrices
Karan Kukreja
 
Introduction to finite element method(fem)
Introduction to finite element method(fem)Introduction to finite element method(fem)
Introduction to finite element method(fem)
Sreekanth G
 
truses and frame
 truses and frame truses and frame
truses and frameUnikl MIMET
 
7.5 lines and_planes_in_space
7.5 lines and_planes_in_space7.5 lines and_planes_in_space
7.5 lines and_planes_in_spaceMahbub Alwathoni
 
FEM: Introduction and Weighted Residual Methods
FEM: Introduction and Weighted Residual MethodsFEM: Introduction and Weighted Residual Methods
FEM: Introduction and Weighted Residual Methods
Mohammad Tawfik
 
engineeringmathematics-iv_unit-ii
engineeringmathematics-iv_unit-iiengineeringmathematics-iv_unit-ii
engineeringmathematics-iv_unit-iiKundan Kumar
 
Stoke’s theorem
Stoke’s theoremStoke’s theorem
Stoke’s theorem
Abhishek Chauhan
 
Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical Methods
Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical MethodsGauss Elimination & Gauss Jordan Methods in Numerical & Statistical Methods
Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical Methods
Janki Shah
 
Sequences and Series (Mathematics)
Sequences and Series (Mathematics) Sequences and Series (Mathematics)
Sequences and Series (Mathematics)
Dhrumil Maniar
 
Frequency response analysis I
Frequency response analysis IFrequency response analysis I
Frequency response analysis I
Mrunal Deshkar
 
Introduction to Finite Elements
Introduction to Finite ElementsIntroduction to Finite Elements
Introduction to Finite Elements
Srinivas Varanasi, Ph.D.
 
Base excitation of dynamic systems
Base excitation of dynamic systemsBase excitation of dynamic systems
Base excitation of dynamic systems
University of Glasgow
 
Half range sine cosine fourier series
Half range sine cosine fourier seriesHalf range sine cosine fourier series
Half range sine cosine fourier seriesHardik Parmar
 
Numerical integration;Gaussian integration one point, two point and three poi...
Numerical integration;Gaussian integration one point, two point and three poi...Numerical integration;Gaussian integration one point, two point and three poi...
Numerical integration;Gaussian integration one point, two point and three poi...
vaibhav tailor
 
Beta gamma functions
Beta gamma functionsBeta gamma functions
Beta gamma functions
Dr. Nirav Vyas
 
MATLAB : Numerical Differention and Integration
MATLAB : Numerical Differention and IntegrationMATLAB : Numerical Differention and Integration
MATLAB : Numerical Differention and Integration
Ainul Islam
 
Finite Element Analysis - UNIT-1
Finite Element Analysis - UNIT-1Finite Element Analysis - UNIT-1
Finite Element Analysis - UNIT-1
propaul
 
Rayleigh Ritz Method
Rayleigh Ritz MethodRayleigh Ritz Method
Rayleigh Ritz Method
Sakthivel Murugan
 

What's hot (20)

System Of Linear Equations
System Of Linear EquationsSystem Of Linear Equations
System Of Linear Equations
 
Taylor series
Taylor seriesTaylor series
Taylor series
 
Matrices
Matrices Matrices
Matrices
 
Introduction to finite element method(fem)
Introduction to finite element method(fem)Introduction to finite element method(fem)
Introduction to finite element method(fem)
 
truses and frame
 truses and frame truses and frame
truses and frame
 
7.5 lines and_planes_in_space
7.5 lines and_planes_in_space7.5 lines and_planes_in_space
7.5 lines and_planes_in_space
 
FEM: Introduction and Weighted Residual Methods
FEM: Introduction and Weighted Residual MethodsFEM: Introduction and Weighted Residual Methods
FEM: Introduction and Weighted Residual Methods
 
engineeringmathematics-iv_unit-ii
engineeringmathematics-iv_unit-iiengineeringmathematics-iv_unit-ii
engineeringmathematics-iv_unit-ii
 
Stoke’s theorem
Stoke’s theoremStoke’s theorem
Stoke’s theorem
 
Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical Methods
Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical MethodsGauss Elimination & Gauss Jordan Methods in Numerical & Statistical Methods
Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical Methods
 
Sequences and Series (Mathematics)
Sequences and Series (Mathematics) Sequences and Series (Mathematics)
Sequences and Series (Mathematics)
 
Frequency response analysis I
Frequency response analysis IFrequency response analysis I
Frequency response analysis I
 
Introduction to Finite Elements
Introduction to Finite ElementsIntroduction to Finite Elements
Introduction to Finite Elements
 
Base excitation of dynamic systems
Base excitation of dynamic systemsBase excitation of dynamic systems
Base excitation of dynamic systems
 
Half range sine cosine fourier series
Half range sine cosine fourier seriesHalf range sine cosine fourier series
Half range sine cosine fourier series
 
Numerical integration;Gaussian integration one point, two point and three poi...
Numerical integration;Gaussian integration one point, two point and three poi...Numerical integration;Gaussian integration one point, two point and three poi...
Numerical integration;Gaussian integration one point, two point and three poi...
 
Beta gamma functions
Beta gamma functionsBeta gamma functions
Beta gamma functions
 
MATLAB : Numerical Differention and Integration
MATLAB : Numerical Differention and IntegrationMATLAB : Numerical Differention and Integration
MATLAB : Numerical Differention and Integration
 
Finite Element Analysis - UNIT-1
Finite Element Analysis - UNIT-1Finite Element Analysis - UNIT-1
Finite Element Analysis - UNIT-1
 
Rayleigh Ritz Method
Rayleigh Ritz MethodRayleigh Ritz Method
Rayleigh Ritz Method
 

Viewers also liked

Exp 5 (1)5. Newton Raphson load flow analysis Matlab Software
Exp 5 (1)5.	Newton Raphson load flow analysis Matlab SoftwareExp 5 (1)5.	Newton Raphson load flow analysis Matlab Software
Exp 5 (1)5. Newton Raphson load flow analysis Matlab Software
Shweta Yadav
 
MATLAB programs Power System Simulation lab (Electrical Engineer)
MATLAB programs Power System Simulation  lab (Electrical Engineer)MATLAB programs Power System Simulation  lab (Electrical Engineer)
MATLAB programs Power System Simulation lab (Electrical Engineer)
Mathankumar S
 
Matlab code for Bisection Method
Matlab code for Bisection MethodMatlab code for Bisection Method
Matlab code for Bisection Method
Taimoor Muzaffar Gondal
 
Matlab simpowersystem
Matlab simpowersystemMatlab simpowersystem
Matlab simpowersystem
Ameen San
 
Sbma 4603 numerical methods Assignment
Sbma 4603 numerical methods AssignmentSbma 4603 numerical methods Assignment
Sbma 4603 numerical methods Assignment
Saidatina Khadijah
 
Bracketing or closed methods
Bracketing or closed methodsBracketing or closed methods
Bracketing or closed methodsandrushow
 
Load Flow Analysis of Jamshoro Thermal Power Station (JTPS) Pakistan Using MA...
Load Flow Analysis of Jamshoro Thermal Power Station (JTPS) Pakistan Using MA...Load Flow Analysis of Jamshoro Thermal Power Station (JTPS) Pakistan Using MA...
Load Flow Analysis of Jamshoro Thermal Power Station (JTPS) Pakistan Using MA...
sunny katyara
 
Introduction to Electrical Engineering Laboratory
Introduction to Electrical Engineering LaboratoryIntroduction to Electrical Engineering Laboratory
Introduction to Electrical Engineering LaboratoryIsuru Premaratne
 
The False-Position Method
The False-Position MethodThe False-Position Method
The False-Position MethodTayyaba Abbas
 
269010454 electrical-machines-lab-manual-for-petrochemaical
269010454 electrical-machines-lab-manual-for-petrochemaical269010454 electrical-machines-lab-manual-for-petrochemaical
269010454 electrical-machines-lab-manual-for-petrochemaical
sampathkumar Mtech Chemical Engg
 
PLC SCADA report Paras Singhal
PLC SCADA report Paras SinghalPLC SCADA report Paras Singhal
PLC SCADA report Paras Singhal
PARAS SINGHAL
 
Regula falsi method
Regula falsi methodRegula falsi method
Regula falsi methodandrushow
 
POWER SYSTEM SIMULATION LAB-1 MANUAL (ELECTRICAL - POWER SYSTEM ENGINEERING )
POWER SYSTEM SIMULATION LAB-1 MANUAL (ELECTRICAL - POWER SYSTEM ENGINEERING )POWER SYSTEM SIMULATION LAB-1 MANUAL (ELECTRICAL - POWER SYSTEM ENGINEERING )
POWER SYSTEM SIMULATION LAB-1 MANUAL (ELECTRICAL - POWER SYSTEM ENGINEERING )
Mathankumar S
 
Exp 3 (1)3. To Formulate YBUS Matrix By Singular Transformation.
Exp 3 (1)3.	To Formulate YBUS Matrix By Singular Transformation.Exp 3 (1)3.	To Formulate YBUS Matrix By Singular Transformation.
Exp 3 (1)3. To Formulate YBUS Matrix By Singular Transformation.
Shweta Yadav
 
Resistor color coding
Resistor color codingResistor color coding
Resistor color coding
Geossip Arnido
 
Em ii lab manual 28.10.08 latest
Em ii lab manual 28.10.08 latestEm ii lab manual 28.10.08 latest
Em ii lab manual 28.10.08 latest
raj_e2004
 
Bisection & Regual falsi methods
Bisection & Regual falsi methodsBisection & Regual falsi methods
Bisection & Regual falsi methods
Divya Bhatia
 

Viewers also liked (20)

Exp 5 (1)5. Newton Raphson load flow analysis Matlab Software
Exp 5 (1)5.	Newton Raphson load flow analysis Matlab SoftwareExp 5 (1)5.	Newton Raphson load flow analysis Matlab Software
Exp 5 (1)5. Newton Raphson load flow analysis Matlab Software
 
MATLAB programs Power System Simulation lab (Electrical Engineer)
MATLAB programs Power System Simulation  lab (Electrical Engineer)MATLAB programs Power System Simulation  lab (Electrical Engineer)
MATLAB programs Power System Simulation lab (Electrical Engineer)
 
Matlab code for Bisection Method
Matlab code for Bisection MethodMatlab code for Bisection Method
Matlab code for Bisection Method
 
Matlab simpowersystem
Matlab simpowersystemMatlab simpowersystem
Matlab simpowersystem
 
Sbma 4603 numerical methods Assignment
Sbma 4603 numerical methods AssignmentSbma 4603 numerical methods Assignment
Sbma 4603 numerical methods Assignment
 
Numerical methods
Numerical methodsNumerical methods
Numerical methods
 
Matlab
MatlabMatlab
Matlab
 
Bracketing or closed methods
Bracketing or closed methodsBracketing or closed methods
Bracketing or closed methods
 
Load Flow Analysis of Jamshoro Thermal Power Station (JTPS) Pakistan Using MA...
Load Flow Analysis of Jamshoro Thermal Power Station (JTPS) Pakistan Using MA...Load Flow Analysis of Jamshoro Thermal Power Station (JTPS) Pakistan Using MA...
Load Flow Analysis of Jamshoro Thermal Power Station (JTPS) Pakistan Using MA...
 
Introduction to Electrical Engineering Laboratory
Introduction to Electrical Engineering LaboratoryIntroduction to Electrical Engineering Laboratory
Introduction to Electrical Engineering Laboratory
 
The False-Position Method
The False-Position MethodThe False-Position Method
The False-Position Method
 
Es272 ch3b
Es272 ch3bEs272 ch3b
Es272 ch3b
 
269010454 electrical-machines-lab-manual-for-petrochemaical
269010454 electrical-machines-lab-manual-for-petrochemaical269010454 electrical-machines-lab-manual-for-petrochemaical
269010454 electrical-machines-lab-manual-for-petrochemaical
 
PLC SCADA report Paras Singhal
PLC SCADA report Paras SinghalPLC SCADA report Paras Singhal
PLC SCADA report Paras Singhal
 
Regula falsi method
Regula falsi methodRegula falsi method
Regula falsi method
 
POWER SYSTEM SIMULATION LAB-1 MANUAL (ELECTRICAL - POWER SYSTEM ENGINEERING )
POWER SYSTEM SIMULATION LAB-1 MANUAL (ELECTRICAL - POWER SYSTEM ENGINEERING )POWER SYSTEM SIMULATION LAB-1 MANUAL (ELECTRICAL - POWER SYSTEM ENGINEERING )
POWER SYSTEM SIMULATION LAB-1 MANUAL (ELECTRICAL - POWER SYSTEM ENGINEERING )
 
Exp 3 (1)3. To Formulate YBUS Matrix By Singular Transformation.
Exp 3 (1)3.	To Formulate YBUS Matrix By Singular Transformation.Exp 3 (1)3.	To Formulate YBUS Matrix By Singular Transformation.
Exp 3 (1)3. To Formulate YBUS Matrix By Singular Transformation.
 
Resistor color coding
Resistor color codingResistor color coding
Resistor color coding
 
Em ii lab manual 28.10.08 latest
Em ii lab manual 28.10.08 latestEm ii lab manual 28.10.08 latest
Em ii lab manual 28.10.08 latest
 
Bisection & Regual falsi methods
Bisection & Regual falsi methodsBisection & Regual falsi methods
Bisection & Regual falsi methods
 

Similar to NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false point,x=g(x)

Incorporate the SOR method in the multigridTest-m and apply the multig.pdf
Incorporate the SOR method in the multigridTest-m and apply the multig.pdfIncorporate the SOR method in the multigridTest-m and apply the multig.pdf
Incorporate the SOR method in the multigridTest-m and apply the multig.pdf
aartechindia
 
Solutions_Manual_to_accompany_Applied_Nu.pdf
Solutions_Manual_to_accompany_Applied_Nu.pdfSolutions_Manual_to_accompany_Applied_Nu.pdf
Solutions_Manual_to_accompany_Applied_Nu.pdf
WaleedHussain30
 
Natural and Clamped Cubic Splines
Natural and Clamped Cubic SplinesNatural and Clamped Cubic Splines
Natural and Clamped Cubic SplinesMark Brandao
 
Banco de preguntas para el ap
Banco de preguntas para el apBanco de preguntas para el ap
Banco de preguntas para el ap
MARCELOCHAVEZ23
 
Raices de ecuaciones
Raices de ecuacionesRaices de ecuaciones
Raices de ecuacionesNatalia
 
Raices de ecuaciones
Raices de ecuacionesRaices de ecuaciones
Raices de ecuacionesNatalia
 
Numerical Algorithm for a few Special Functions
Numerical Algorithm for a few Special FunctionsNumerical Algorithm for a few Special Functions
Numerical Algorithm for a few Special Functions
Amos Tsai
 
System dynamics 3rd edition palm solutions manual
System dynamics 3rd edition palm solutions manualSystem dynamics 3rd edition palm solutions manual
System dynamics 3rd edition palm solutions manual
SextonMales
 
Taylor and maclaurian series
Taylor and maclaurian seriesTaylor and maclaurian series
Taylor and maclaurian series
Nishant Patel
 
Recursion in C
Recursion in CRecursion in C
Recursion in C
Lakshmi Sarvani Videla
 
C PROGRAMS - SARASWATHI RAMALINGAM
C PROGRAMS - SARASWATHI RAMALINGAMC PROGRAMS - SARASWATHI RAMALINGAM
C PROGRAMS - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
Fourier series example
Fourier series exampleFourier series example
Fourier series exampleAbi finni
 
Applied numerical methods lec10
Applied numerical methods lec10Applied numerical methods lec10
Applied numerical methods lec10
Yasser Ahmed
 
Bca3010 computer oreineted numerical methods
Bca3010   computer oreineted numerical methodsBca3010   computer oreineted numerical methods
Bca3010 computer oreineted numerical methodssmumbahelp
 
Scilab presentation
Scilab presentation Scilab presentation
Scilab presentation
Nasir Ansari
 
Econometric Analysis 8th Edition Greene Solutions Manual
Econometric Analysis 8th Edition Greene Solutions ManualEconometric Analysis 8th Edition Greene Solutions Manual
Econometric Analysis 8th Edition Greene Solutions Manual
LewisSimmonss
 
Mid-Term ExamName___________________________________MU.docx
Mid-Term ExamName___________________________________MU.docxMid-Term ExamName___________________________________MU.docx
Mid-Term ExamName___________________________________MU.docx
annandleola
 

Similar to NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false point,x=g(x) (20)

Numerical methods generating polynomial
Numerical methods generating polynomialNumerical methods generating polynomial
Numerical methods generating polynomial
 
Incorporate the SOR method in the multigridTest-m and apply the multig.pdf
Incorporate the SOR method in the multigridTest-m and apply the multig.pdfIncorporate the SOR method in the multigridTest-m and apply the multig.pdf
Incorporate the SOR method in the multigridTest-m and apply the multig.pdf
 
Solutions_Manual_to_accompany_Applied_Nu.pdf
Solutions_Manual_to_accompany_Applied_Nu.pdfSolutions_Manual_to_accompany_Applied_Nu.pdf
Solutions_Manual_to_accompany_Applied_Nu.pdf
 
Natural and Clamped Cubic Splines
Natural and Clamped Cubic SplinesNatural and Clamped Cubic Splines
Natural and Clamped Cubic Splines
 
Banco de preguntas para el ap
Banco de preguntas para el apBanco de preguntas para el ap
Banco de preguntas para el ap
 
Raices de ecuaciones
Raices de ecuacionesRaices de ecuaciones
Raices de ecuaciones
 
Raices de ecuaciones
Raices de ecuacionesRaices de ecuaciones
Raices de ecuaciones
 
Numerical Algorithm for a few Special Functions
Numerical Algorithm for a few Special FunctionsNumerical Algorithm for a few Special Functions
Numerical Algorithm for a few Special Functions
 
System dynamics 3rd edition palm solutions manual
System dynamics 3rd edition palm solutions manualSystem dynamics 3rd edition palm solutions manual
System dynamics 3rd edition palm solutions manual
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
Taylor and maclaurian series
Taylor and maclaurian seriesTaylor and maclaurian series
Taylor and maclaurian series
 
Recursion in C
Recursion in CRecursion in C
Recursion in C
 
C PROGRAMS - SARASWATHI RAMALINGAM
C PROGRAMS - SARASWATHI RAMALINGAMC PROGRAMS - SARASWATHI RAMALINGAM
C PROGRAMS - SARASWATHI RAMALINGAM
 
Fourier series example
Fourier series exampleFourier series example
Fourier series example
 
Applied numerical methods lec10
Applied numerical methods lec10Applied numerical methods lec10
Applied numerical methods lec10
 
Bca3010 computer oreineted numerical methods
Bca3010   computer oreineted numerical methodsBca3010   computer oreineted numerical methods
Bca3010 computer oreineted numerical methods
 
Scilab presentation
Scilab presentation Scilab presentation
Scilab presentation
 
Econometric Analysis 8th Edition Greene Solutions Manual
Econometric Analysis 8th Edition Greene Solutions ManualEconometric Analysis 8th Edition Greene Solutions Manual
Econometric Analysis 8th Edition Greene Solutions Manual
 
Mid-Term ExamName___________________________________MU.docx
Mid-Term ExamName___________________________________MU.docxMid-Term ExamName___________________________________MU.docx
Mid-Term ExamName___________________________________MU.docx
 
Vcs16
Vcs16Vcs16
Vcs16
 

Recently uploaded

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 

Recently uploaded (20)

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 

NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false point,x=g(x)

  • 1. Islamic Azad University Qazvin Branch Faculty of Industrial and Mechanics , Department of Mechanical Engineering Subject Compare Some Algorithms for Solving Nonlinear Equation Thesis Advisor Dr.Marufi By Parham Sagharichi Ha
  • 2. Assignment of Numerical Analysis Parham Sagharichi Ha parhamsagharchi@gmail.com 1 Problem The speed v of a Saturn V rocket in vertical flight near the surface of earth can be approximated by 𝑣 = 𝑢 ln 𝑀0 𝑀0 − 𝑚̇ 𝑡 − 𝑔𝑡 𝑢 = 2510 𝑚 𝑠 = 𝑣𝑒𝑙𝑜𝑐𝑖𝑡𝑦 𝑜𝑓 𝑒𝑥ℎ𝑎𝑢𝑠𝑡 𝑟𝑒𝑙𝑎𝑡𝑖𝑣𝑒 𝑡𝑜 𝑡ℎ𝑒 𝑟𝑜𝑐𝑘𝑒𝑡 𝑀0 = 2.8 ∗ 106 𝑘𝑔 = 𝑚𝑎𝑠𝑠 𝑜𝑓 𝑟𝑜𝑐𝑘𝑒𝑡 𝑎𝑡 𝑙𝑖𝑓𝑡𝑜𝑓𝑓 𝑚̇ = 13.3 ∗ 103 𝑘𝑔 𝑠 = 𝑟𝑎𝑡𝑒 𝑜𝑓 𝑓𝑢𝑒𝑙 𝑐𝑜𝑛𝑠𝑢𝑚𝑝𝑡𝑖𝑜𝑛 𝑔 = 9.81 𝑚 𝑠2 = 𝑔𝑟𝑎𝑣𝑖𝑡𝑎𝑡𝑖𝑜𝑛𝑎𝑙 𝑎𝑐𝑐𝑒𝑙𝑒𝑟𝑎𝑡𝑖𝑜𝑛 𝑡 = 𝑡𝑖𝑚𝑒 Determine the time when the rocket reaches the speed of sound (335 m/s). Solution 𝑢 𝑙𝑛 𝑀0 𝑀0 − 𝑚̇ 𝑡 − 𝑔𝑡 − 𝑣 = 0 Now we want to determine time in the above equation
  • 3. Assignment of Numerical Analysis Parham Sagharichi Ha parhamsagharchi@gmail.com 2 Matlab 1) Bisection Method Script : clc close all clear all %% % Subject : Bisect Algorithm % Author: Parham Sagharichi Ha Email : parhamsagharchi@gmail.com %% %-------------------S------T------A------R------T------------ -------------% global tolerance tolerance = 1e-4; % for example : 1e-4 = 10^-4 u = 2510; M0 = 2.8*10^6; mdot = 13.3*10^3; g = 9.81; v = 335; xlower = 0; xupper = 100; myfun = @(t)(u.*log(M0./(M0-mdot.*t))-g.*t-v); [root,iflag] = fbisect(myfun,xlower,xupper); switch iflag case -2 disp('Initial range does not only contain one root') otherwise disp([' Root = ' num2str(root) ... ' found in ' num2str(iflag) ' iterations']) end %---------------F------I------N------I------S------H--------- -------------%
  • 4. Assignment of Numerical Analysis Parham Sagharichi Ha parhamsagharchi@gmail.com 3 Function : function [root,iflag] = fbisect(myfun,a,b) if a>=b disp(' attention b>a in [a b] ') return end global tolerance x = a:0.001:b; y = feval(myfun,x); fa = y(1); fb = y(end); ymax = max(y); ymin = min(y); figure plot(x,y) grid on hold on plot([a a],[ymin ymax]) plot([b b],[ymin ymax]) iflag = 0; iterations = 0 ; while (fa*fb<0) & (b-a)>tolerance iterations = iterations + 1; c = (a+b)/2; fc = feval(myfun,c); plot([c c],[ymin ymax]) pause if fa*fc<0 b = c; fb = fc; elseif fa*fc>0 a = c; fa = fc; else iflag = 1; root = c return end end switch iterations case 0 iflag = -2; root = NaN; otherwise iflag = iterations; root = c; end
  • 5. Assignment of Numerical Analysis Parham Sagharichi Ha parhamsagharchi@gmail.com 4 Result : Root = 70.8779 found in 20 iterations 2) Linear Interpolation (False Position) Method : Script : clc close all clear all %% % Subject : False Postion Algorithm % Author: Parham Sagharichi Ha Email : parhamsagharchi@gmail.com %% %-------------------S------T------A------R------T------------ -------------% global tolerance tolerance = 1e-4; % for example : 1e-4 = 10^-4 u = 2510; M0 = 2.8*10^6; mdot = 13.3*10^3; g = 9.81; v = 335; xlower = 0; xupper = 100; myfun = @(t)(u.*log(M0./(M0-mdot.*t))-g.*t-v); [root,iflag] = finter(myfun,xlower,xupper); switch iflag case -2 disp('Initial range does not only contain one root') otherwise disp([' Root = ' num2str(root) ... ' found in ' num2str(iflag) ' iterations']) end %---------------F------I------N------I------S------H--------- -------------%
  • 6. Assignment of Numerical Analysis Parham Sagharichi Ha parhamsagharchi@gmail.com 5 Function : function [root,iflag] = finter(myfun,a,b) if a>=b disp(' attention b>a in [a b] ') return end global tolerance x = a:0.001:b; y = feval(myfun,x); fa = y(1); fb = y(end); ymax = max(y); ymin = min(y); figure plot(x,y) grid on hold on plot([a a],[ymin ymax]) plot([b b],[ymin ymax]) iflag = 0; iterations = 0 ; while (fa*fb<0) & (b-a)>tolerance iterations = iterations + 1; c = b - (fb)*(a-b)/(fa-fb); fc = feval(myfun,c); plot([c c],[ymin ymax]) pause if fa*fc<0 b = c; fb = fc; elseif fa*fc>0 a = c; fa = fc; else iflag = 1; root = c return end end switch iterations case 0 iflag = -2; root = NaN; otherwise
  • 7. Assignment of Numerical Analysis Parham Sagharichi Ha parhamsagharchi@gmail.com 6 iflag = iterations; root = c; end Result : Root = 70.878 found in 24 iterations 3) Newton-Raphson Method : Script : clc close all clear all %% % Subject : Newton_Raphson Algorithm % Author: Parham Sagharichi Ha Email : parhamsagharchi@gmail.com %% %-------------------S------T------A------R------T------------ -------------% format short E tolerance = 1e-4; % for example : 1e-4 = 10^-4 xlower = 0; xupper = 100; xguess = 45; if (xguess>xupper)||(xlower>xguess) disp(' error , repate again ') return end xrange = xlower:0.1:xupper; s = size(xrange); u = 2510; M0 = 2.8*10^6; mdot = 13.3*10^3; g = 9.81; v = 335; syms x myfun = u.*log(M0./(M0-mdot.*x))-g.*x-v;
  • 8. Assignment of Numerical Analysis Parham Sagharichi Ha parhamsagharchi@gmail.com 7 u = 2510; M0 = 2.8*10^6; mdot = 13.3*10^3; g = 9.81; v = 335; for i = 1:s(2); y(i) = double(subs(myfun,[x],[xrange(i)])); end fa = y(1); fb = y(end); ymax = max(y); ymin = min(y); figure plot(xrange,y) grid on hold on plot([xlower xlower],[ymin ymax]) plot([xupper xupper],[ymin ymax]) plot([xlower xupper],[0 0]) iflag = 0; iterations = 1 ; f = double(subs(myfun,[x],xguess)); myfun_prime = jacobian(myfun,x); fprime = double(subs(myfun_prime,[x],xguess)); xn = xguess; xnew = xn - f/fprime; plot([xn xn],[0 f]) pause plot([xn xnew],[f 0]) while (abs(xnew-xn)>tolerance) & (iterations<30) iterations = iterations + 1; xn = xnew; f = double(subs(myfun,[x],xn)); fprime = double(subs(myfun_prime,[x],xn)); xnew = xn - f/fprime; root = xnew; pause plot([xn xn],[0 f]) pause plot([xn xnew],[f 0]) end
  • 9. Assignment of Numerical Analysis Parham Sagharichi Ha parhamsagharchi@gmail.com 8 switch iterations case 30 disp(' Not root found '); otherwise disp([' Root = ' num2str(root) ... ' found in ' num2str(iterations) ' iterations ']) end %---------------F------I------N------I------S------H--------- -------------% Result : Root = 70.878 found in 5 iterations 4) Mueller’s Method : Script : clc close all clear all %% % Subject : Mueller’s Algorithm % Author: Parham Sagharichi Ha Email : parhamsagharchi@gmail.com %% %-------------------S------T------A------R------T------------ -------------% tolerance = 1e-4; % for example : 1e-4 = 10^-4 u = 2510; M0 = 2.8*10^6; mdot = 13.3*10^3; g = 9.81; v = 335; xlower = 0; xupper = 100;
  • 10. Assignment of Numerical Analysis Parham Sagharichi Ha parhamsagharchi@gmail.com 9 xguess = 45; if (xguess>xupper)||(xlower>xguess) disp(' error , repate again ') return end myfun = @(t)(u.*log(M0./(M0-mdot.*t))-g.*t-v); x = [xlower xguess xupper]';%[x2 x0 x1] xe = xlower:0.1:xupper; ye = feval(myfun,xe); ymax = max(ye); ymin = min(ye); figure plot(xe,ye) grid on hold on rline = plot([xlower xlower],[ymin ymax]); mline = plot([xguess xguess],[ymin ymax]); fline = plot([xupper xupper],[ymin ymax]); pause iterations = 0; while (true) iterations = iterations +1; y = feval(myfun,x);%[f2 f0 f1] h1 = x(3)-x(2); h2 = x(2)-x(1); gamma = h2/h1; c = y(2); a = (gamma*y(3)-y(2)*(1+gamma)+y(1))/(gamma*h1^2*(1+gamma)); b = (y(3)-y(2)-a*h1^2)/h1; if b>0 root = x(2)-(2*c)/(b+sqrt(b^2-4*a*c)); else root = x(2)-(2*c)/(b-sqrt(b^2-4*a*c)); end pause rootline = plot([root root],[ymin ymax]); if root>x(2) x = [x(2) root x(3)]; else x = [x(1) root x(2)]; end pause delete(rootline) delete(rline) delete(mline) delete(fline)
  • 11. Assignment of Numerical Analysis Parham Sagharichi Ha parhamsagharchi@gmail.com 10 rline = plot([x(1) x(1)],[ymin ymax]); mline = plot([x(2) x(2)],[ymin ymax]); fline = plot([x(3) x(3)],[ymin ymax]); if (abs(feval(myfun,root))<(10^-8))&(iterations<30) break end end switch iterations case 30 disp(' Not root found '); otherwise disp([' Root = ' num2str(root) ... ' found in ' num2str(iterations) ' iterations ']) end Result : Root = 70.878 found in 5 iterations 5) 𝑥 = 𝑔(𝑥) Method : 𝑢 𝑙𝑛 𝑀0 𝑀0 − 𝑚̇ 𝑡 − 𝑔𝑡 − 𝑣 = 0 First Equation : 𝑡 = 𝑢 𝑔 𝑙𝑛 𝑀0 𝑀0 − 𝑚̇ 𝑡 − 𝑣 𝑔 Second Equation : 𝑡 = 𝑀0 𝑚̇ ( exp ( 𝑔𝑡 + 𝑣 𝑢 ) − 1 exp ( 𝑔𝑡 + 𝑣 𝑢 ) )
  • 12. Assignment of Numerical Analysis Parham Sagharichi Ha parhamsagharchi@gmail.com 11 Script : clc close all clear all %% % Subject : x=g(x) Algorithm % Author: Parham Sagharichi Ha Email : parhamsagharchi@gmail.com %% %-------------------S------T------A------R------T------------ -------------% tolerance = 1e-4; % for example : 1e-4 = 10^-4 u = 2510; M0 = 2.8*10^6; mdot = 13.3*10^3; g = 9.81; v = 335; xlower = 0; xupper = 100; xguess = 45; if (xguess>xupper)||(xlower>xguess) disp(' error , repate again ') return end myfun1 = @(t)((u/g).*log(M0./(M0-mdot.*t))-v/g); myfun2 = @(t)((M0/mdot).*(exp((g.*t+v)/u)- 1)./exp((g.*t+v)/u)); xold1 = xguess; xnew1 = feval(myfun1,xold1); iterations1 = 0; while (abs(xnew1-xold1)>tolerance)&(iterations1<30) iterations1 = iterations1 + 1; xold1 = xnew1; xnew1 = feval(myfun1,xold1);
  • 13. Assignment of Numerical Analysis Parham Sagharichi Ha parhamsagharchi@gmail.com 12 end root1 = xnew1(end); switch iterations1 case 30 disp(' Not root found '); otherwise disp([' Root1 = ' num2str(root1) ... ' found in ' num2str(iterations1) ' iterations1 ']) end xold2 = xguess; xnew2 = feval(myfun2,xold2); iterations2 = 0; while (abs(xnew2-xold2)>tolerance)&(iterations2<30) iterations2 = iterations2 + 1; xold2 = xnew2; xnew2 = feval(myfun2,xold2); end root2 = xnew2(end) switch iterations2 case 30 disp(' Not root found '); otherwise disp([' Root2 = ' num2str(root2) ... ' found in ' num2str(iterations2) ' iterations2 ']) end Result : Not root found root2 = 7.0878e+01 Root2 = 70.8779 found in 20 iterations2 References Kiusalaas, J. (2009) Numerical Methods in Engineering with MATLAB®