ENGT5140 Numerical Techniques: Root Finding and ODE Solutions
VerifiedAdded on 2025/04/07
|12
|401
|189
AI Summary
Desklib provides past papers and solved assignments for students. This solved assignment covers numerical methods.

ENGT5140
Numerical Techniques in Engineering
Numerical Techniques in Engineering
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Contents
1..................................................................................................................................................................3
(a)............................................................................................................................................................3
(b)............................................................................................................................................................4
6..................................................................................................................................................................7
(a)............................................................................................................................................................7
(b)............................................................................................................................................................7
8..................................................................................................................................................................9
(a)............................................................................................................................................................9
(b)............................................................................................................................................................9
9................................................................................................................................................................10
(a)..........................................................................................................................................................10
(b)..........................................................................................................................................................10
(c)...........................................................................................................................................................11
1..................................................................................................................................................................3
(a)............................................................................................................................................................3
(b)............................................................................................................................................................4
6..................................................................................................................................................................7
(a)............................................................................................................................................................7
(b)............................................................................................................................................................7
8..................................................................................................................................................................9
(a)............................................................................................................................................................9
(b)............................................................................................................................................................9
9................................................................................................................................................................10
(a)..........................................................................................................................................................10
(b)..........................................................................................................................................................10
(c)...........................................................................................................................................................11

1.
Code:
function [value] = func(x)
value = 14*x.*exp(x-2) - 12*exp(x-2) - 7*x.^3 + 20*x.^2 - 26*x + 12;
end
% func_prime.m
function [value] = func_prime(x)
value = 14*x*exp(x-2) + 14*exp(x-2) -12*exp(x-2) -21*x^2 +40*x -26;
end
% Newton_Raphson.m
x = input('Starting guess :');
tolerance = 1e-8;
iterations = 0;
while (iterations<30) & (abs(func(x))>tolerance)
x = x-func(x)/func_prime(x);
iterations = iterations + 1;
end
if iterations==30
disp('No root found')
else
disp(['Root =',num2str(x,10) ,'(found in ', int2str(iterations),'
iterations.)'])
end
(a)
i.
Code:
function [value] = func(x)
value = 14*x.*exp(x-2) - 12*exp(x-2) - 7*x.^3 + 20*x.^2 - 26*x + 12;
end
% func_prime.m
function [value] = func_prime(x)
value = 14*x*exp(x-2) + 14*exp(x-2) -12*exp(x-2) -21*x^2 +40*x -26;
end
% Newton_Raphson.m
x = input('Starting guess :');
tolerance = 1e-8;
iterations = 0;
while (iterations<30) & (abs(func(x))>tolerance)
x = x-func(x)/func_prime(x);
iterations = iterations + 1;
end
if iterations==30
disp('No root found')
else
disp(['Root =',num2str(x,10) ,'(found in ', int2str(iterations),'
iterations.)'])
end
(a)
i.
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

ii.
Root 1
Root 2
Root 1
Root 2
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

iii.
Root 2 converges linearly but other doesn’t.
(b)
function [value] = func1(x)
value = nthroot((1-3/4*x),3);
end
% func_prime.m
function [value] = func_prime1(x)
value = 14*x*exp(x-2) + 14*exp(x-2) -12*exp(x-2) -21*x^2 +40*x -26;
end
% Newton_Raphson.m
x = input('Starting guess :');
tolerance = 1e-8;
iterations = 0;
while (iterations<50) & (abs(func(x))>tolerance)
x = x-func1(x)/func_prime1(x);
iterations = iterations + 1;
end
if iterations==50
disp('No root found')
else
disp(['Root =',num2str(x,10) ,'(found in ', int2str(iterations),'
iterations.)'])
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Root 2 converges linearly but other doesn’t.
(b)
function [value] = func1(x)
value = nthroot((1-3/4*x),3);
end
% func_prime.m
function [value] = func_prime1(x)
value = 14*x*exp(x-2) + 14*exp(x-2) -12*exp(x-2) -21*x^2 +40*x -26;
end
% Newton_Raphson.m
x = input('Starting guess :');
tolerance = 1e-8;
iterations = 0;
while (iterations<50) & (abs(func(x))>tolerance)
x = x-func1(x)/func_prime1(x);
iterations = iterations + 1;
end
if iterations==50
disp('No root found')
else
disp(['Root =',num2str(x,10) ,'(found in ', int2str(iterations),'
iterations.)'])
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Plot
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

6
(a)
function [t,y] = ode_RK4(f,tspan,y0,N,varargin)
%Runge-Kutta method to solve vector differential eqn y’(t) = f(t,y(t))
% for tspan = [t0,tf] and with the initial value y0 and N time steps
if nargin < 4 || N <= 0, N = 100; end
if nargin < 3, y0 = 0; end
y(1,:) = y0(:)'; %make it a row vector
h = (tspan(2) - tspan(1))/N; t = tspan(1)+[0:N]'*h;
for k = 1:N
f1 = h*feval(f,t(k),y(k,:),varargin{:}); f1 = f1(:)';
f2 = h*feval(f,t(k) + h/2,y(k,:) + f1/2,varargin{:}); f2 = f2(:)';
f3 = h*feval(f,t(k) + h/2,y(k,:) + f2/2,varargin{:}); f3 = f3(:)';
f4 = h*feval(f,t(k) + h,y(k,:) + f3,varargin{:}); f4 = f4(:)';
y(k + 1,:) = y(k,:) + (f1 + 2*(f2 + f3) + f4)/6;
end
(b)
clear all
tspan = [1 10];
N=200;
f = inline('[y(2); (0.12 ./t)*(1+ y(1).^2)^1/2]','t','y');
[t1,yr] = ode_RK4(f,tspan,[100 25],N);
(a)
function [t,y] = ode_RK4(f,tspan,y0,N,varargin)
%Runge-Kutta method to solve vector differential eqn y’(t) = f(t,y(t))
% for tspan = [t0,tf] and with the initial value y0 and N time steps
if nargin < 4 || N <= 0, N = 100; end
if nargin < 3, y0 = 0; end
y(1,:) = y0(:)'; %make it a row vector
h = (tspan(2) - tspan(1))/N; t = tspan(1)+[0:N]'*h;
for k = 1:N
f1 = h*feval(f,t(k),y(k,:),varargin{:}); f1 = f1(:)';
f2 = h*feval(f,t(k) + h/2,y(k,:) + f1/2,varargin{:}); f2 = f2(:)';
f3 = h*feval(f,t(k) + h/2,y(k,:) + f2/2,varargin{:}); f3 = f3(:)';
f4 = h*feval(f,t(k) + h,y(k,:) + f3,varargin{:}); f4 = f4(:)';
y(k + 1,:) = y(k,:) + (f1 + 2*(f2 + f3) + f4)/6;
end
(b)
clear all
tspan = [1 10];
N=200;
f = inline('[y(2); (0.12 ./t)*(1+ y(1).^2)^1/2]','t','y');
[t1,yr] = ode_RK4(f,tspan,[100 25],N);
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser


8
(a)
[t,n]=ode45(@equation,[1 2],[1/3 1/12]);
n(length(t))
plot(n(:,1))
hold on
c=size(n);
g=linspace(1/3,1/12,c(1));
g1=1/3*(t).^2;
plot(g1)
(b)
Values are very much deviating as
1/3*t(1)^2=0.33
(a)
[t,n]=ode45(@equation,[1 2],[1/3 1/12]);
n(length(t))
plot(n(:,1))
hold on
c=size(n);
g=linspace(1/3,1/12,c(1));
g1=1/3*(t).^2;
plot(g1)
(b)
Values are very much deviating as
1/3*t(1)^2=0.33
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

9
(a)
A=[0 1 1 1; 1 0 1 1;1 1 0 1; 1 1 1 0];
h=5;
B=[4; 4; 4; 4].*(1/h^2)-[0;0;0;100]
T=A\B
(b)
H=2.5
H=0.25
(a)
A=[0 1 1 1; 1 0 1 1;1 1 0 1; 1 1 1 0];
h=5;
B=[4; 4; 4; 4].*(1/h^2)-[0;0;0;100]
T=A\B
(b)
H=2.5
H=0.25
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

H=0.025
H=0.0025
Decreasing the size of grid increase value of t.
(c)
x=1; h=2.5
H=0.0025
Decreasing the size of grid increase value of t.
(c)
x=1; h=2.5

y=1;
x=1; h=2.5;
y=1;
x=1; h=2.5;
y=1;
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide
1 out of 12
Related Documents

Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.