Professional Documents
Culture Documents
Assignment 2 Mac2022
Assignment 2 Mac2022
ASSIGNMENT 2
2. Use the provided format for the cover page and answer template.
4. Answers WITHOUT computational approach or simulation tool will result in ZERO marks.
Each student needs to send in a softcopy of the assignment through MS TEAMS / GOOGLE
CLASSROOM / UFUTURE at your respective class setting not later than 15 JULY 2022 (11:59
PM) with the file name:
5.
a) NameStudent.pdf (Report)
b) NameStudent.m (m.file)
*only insert the information in blue.
This assignment is designed for Course Outcome 3 (CO3) and 4 (CO4) of the course:
CO3: Evaluate the numerical techniques in solving engineering problems [PO3] {C6}.
PO3: Able to design solutions for complex engineering problems and design systems, components
or processes that meet specified needs with appropriate consideration for public health and safety,
6. cultural, societal, environmental considerations (WK5).
CO4: Construct computational approach to solve mathematical problems [PO5] {P4}.
PO5: Able to Create, select and apply appropriate techniques, resources, and modern engineering
and IT tools, including prediction and modelling, to complex engineering problems, with an
understanding of the limitations (WK6).
UNIVERSITI TEKNOLOGI MARA
ASSIGNMENT 2
No Name Student ID
1 MUHAMMAD AIMAN NAQIE BIN ABD MUTALIB 2019229762
Allocated
ITEM CO / PO Assessment Criteria (Report) Marks
Marks
1 CO3/PO3/C5 Defining problems, methods, and criteria 3.0
TOTAL 20%
1. Choose ONE engineering case study that requires solving Ordinary Differential Equation (ODE)
in its analysis. Include any relevant diagrams or figures to illustrate the problem. Identify TWO
ODE methods that can be used in solving the problem. Briefly describe the theory involved.
Consider s simply supported beam as shown below. The deflection, y, of the centreline of the beam
as a function of the position, x, is given by following equation.
𝑤0 𝑥
𝑦= (7𝐿4 − 10𝐿2 𝑥 2 + 3𝑥 4 )
360𝐿𝐸𝐼
Where,
𝑤0 = 20 𝑘𝑁⁄𝑚
Find the position, x, at which the deflection of the beam is maximum and the deflection at that point
using following methods:
1. Shooting Method
2. Finite-Difference Method
𝑑𝑦
[Hint: The maximum deflection is at a point where 𝑑𝑥 = 0]
[CO3: 3 MARKS]
2. Solve the ODE problem using Matlab/Octave. Display a snapshot of the .m file.
1. Shooting Method:
[CO4: 3 MARKS]
The highest deflection will be 0.022246 at a length of 3.2 meters and the lowest deflection for true value
at 0.0087317 at a length of 2.4 meters.
Figure 2: Graph of Deflection vs Length
[CO3: 2 MARKS]
Report the results clearly and identify Does not identify the solution to the
underlying issues. problem.
*Make sure to make proper labelling for your plot.
METHOD 2
4. Solve the ODE problem using Matlab/Octave. Display a snapshot of the .m file.
2. Finite-Difference Method
[CO4: 3 MARKS]
From the graph of deflection(m) versus length(m) of finite-difference method above, we can see that
the true value of deflection is slightly higher than the approximate value that we got from using
finite-difference method. It shows that the finite-difference method is numerically more stable to use
since the approximate value is closer to the true value.
[CO3: 2 MARKS]
Report the results clearly and identify Does not identify the solution to the
underlying issues. problem.
*Make sure to make proper labelling for your plot.
6. Runtime of .m file (to be assessed by the lecturer)
1. Shooting Method
clear;
clc
%Shooting Method%
%ODE d2y=0.0002504*x^3-0.003601*x%
%let z=dy/dx (f1)%
%dz=0.0002504*x^3-0.003601*x (f2)%
f2=@(x) 0.0002504.*x.^3-0.003601.*x;
f1=@(z) z;
%initial value%
h=0.8;
x=[0:h:4];
[row,node]=size(x); %node count%
y=zeros(4,node);
z=zeros(1,node);
%true value of y
y(4,:)=0.000003751.*x.*(1792-160.*x.^2+3.*x.^4);
y(4,node)=0;
for j=2:node
y(i,j)=y(i,j-1)+f1(z(j-1))*h;
z(j)=z(j-1)+f2(x(j-1))*h;
end
yNew(i)=y(i,j);
zNew(i)=z(j);
fprintf("Result: z=%f\n\t\ty=%f\n",zNew(i),yNew(i));
end
fprintf("\nTabulated result:");
T=table(x',y(1,:)',y(2,:)',y(3,:)',y(4,:)');
T.Properties.VariableNames={'Length','The_1_Guess','The_2_Guess','The_Final_hit','True_Value'}
hold on;
plot(x,y(1,:));
plot(x,y(2,:));
plot(x,y(3,:));
plot(x,y(4,:));
hold off
grid on
xlabel('Length(m)');
ylabel('Deflection(m)');
title('Graph of Deflection(m) Versus Length(m)');
legend('Guess1','Guess2','Shooting','True');
2. Finite Difference Method
clear;
clc
%Initial value%
h=0.8; %step size%
x=[0:h:4];
[row,node]=size(x); %get number of node%
y=zeros(1,node); %deflection value%
%True Value%
yTrue=0.000003751.*x.*(1792-160.*x.^2+3.*x.^4);
yTrue(node)=0;
%matrix to hold calculation value at each node%
%node+1 correspond to y0-y4 and RHS value%
fdm=zeros(node,node+1);
%RHS%
d2y=@(x) (0.0002504*x^3-0.003601*x)*h^2;
fprintf("\n\nCalculation");
for i=2:node-1
%LHS%
fdm(i,i+1)=1;
fdm(i,i)=-2;
fdm(i,i-1)=1;
%RHS%
fdm(i,node+1)=d2y(x(i));
fprintf("\nNode=%d\tx=%0.2f\n",i,x(i));
fprintf("y%d-2y%d+y%d=%f\n",i,i-1,i-2,fdm(i,node+1));
end
fdm
fprintf("\n\n");
for j=i+1:node
fdm(j,:)=fdm(j,:)-fdm(i,:)*fdm(j,i);
end
end
k=0;
for j=node-1:-1:i
y(i)=y(i)-fdm(i,node-k)*y(j+1);
k=k+1;
end
end
fdm
fprintf("\n\n");
digits(3);
y=y';
x=x';
yTrue=yTrue';
T=table(x,y,yTrue);
T.Properties.VariableNames={'Length','Approxiamate_value_of_deflection','true_value_of_deflection'}
hold on;
plot(x,y);
plot(x,yTrue);
hold off
grid on
xlabel('Length(m)');
ylabel('Deflection(m)');
[CO4: 3 MARKS]
Executes without errors, excellent user Does not execute due to syntax errors/runtime
prompts, good use of symbols, and spacing errors (endless loop, crashes etc.) User prompts
in output. are misleading or non-existent.
7. Discuss the results by comparing the methods used to solve the ODE problem. Summarize the
results of your analysis and include your final answer in the proper SI unit.
Both the shooting method and the finite difference method use numbers to approximatively
solve a boundary value problem (BVP) to a specified accuracy. In this study, both approaches were
used in MATLAB and contrasted against one another on a BVP. The finite difference approach was
shown to be numerically more stable and to converge more quickly than the shotting method. Figure
4 can be used to demonstrate this. At a distance of 4 metres, the finite difference approach exhibits a
maximum deflection of 0, whereas the shooting method exhibits a deflection of 0.056196. The graph
demonstrates that the finite difference method is significantly superior to the shooting method since
the approximate value of deflection for each distance is close to the true values.
Additionally, according to Table 1, the true error for the shooting method is 72.17 percent,
while the true error for the finite difference approach is 6.52 percent at 3.2 metres. Apart from that,
the photography process takes time because we must experiment till, we get the perfect shot.
Consequently, it demonstrates that the finite difference method is superior to the shooting method and
can serve as another way to solve the problems. As a result, in accordance with the problem's
description, the distance of x when the maximum deflection at dy/dx=0 is at 4m.
Finding approximations of solutions to non-linear BVPs can be done effectively using both
the shooting and the finite-difference approaches. In comparison to the shooting approach, the results
demonstrate that the finite-difference method is numerically more stable and converges. The finite
difference method is also trickier to put into practise. The finite difference approach should be
employed when trying to find approximate solutions with a low error threshold; otherwise, the
shooting method is preferable.
[CO2: 4 MARKS]
Report the results clearly and identify
Does not identify the solution to the problem.
underlying issues.