Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

UNIVERSITI TEKNOLOGI MARA

ASSIGNMENT 2

COURSE : NUMERICAL METHODS WITH APPLICATIONS


COURSE CODE : MEC500
DEADLINE : WEEK 14
MODE : GROUP ASSIGNMENT

GROUP ASSIGNMENT GUIDELINES

1. Answer ALL questions in ENGLISH.

2. Use the provided format for the cover page and answer template.

It is COMPULSORY to use computational tools (MATLAB/OCTAVE) to complete this


3.
assignment.

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

COURSE : NUMERICAL METHODS WITH APPLICATIONS


COURSE CODE : MEC500
DEADLINE : WEEK 14
MODE : GROUP ASSIGNMENT

GROUP NO DUE DATE SUBMISSION DATE REMARKS


EMD6M5B (2) 29th JULY 2021 29th JULY 2021

LECTURER NAME DR. HAFIZI BIN LUQMAN

No Name Student ID
1 MUHAMMAD AIMAN NAQIE BIN ABD MUTALIB 2019229762

2 MUHAMMAD AMIR SABRIN BIN AZNAN 2019416468

3 MUHAMMAD AIDIL SYUKRI BIN MOHD NOOR 2019295174

4 MUHAMMAD DANIAL IEMAN BIN ROSDAN 2019268942

5 SYAFIQ BIN SABRAN HASNAN 2019207628

Allocated
ITEM CO / PO Assessment Criteria (Report) Marks
Marks
1 CO3/PO3/C5 Defining problems, methods, and criteria 3.0

2 CO4/PO5/P4 Display computational approach (METHOD 1) 3.0

3 CO3/PO3/C5 Reporting the findings (METHOD 1) 2.0

4 CO4/PO5/P4 Display computational approach (METHOD 2) 3.0

5 CO3/PO3/C5 Reporting the findings (METHOD 2) 2.0

6 CO4/PO5/P4 Execution of computational approach 3.0

7 CO3/PO3/C5 Discussion and conclusions 4.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,

Length of the beam, 𝐿 = 4 𝑚

Elastic Modulus, 𝐸 = 70 𝐺𝑃𝑎

Moment of Inertia, 𝐼 = 52.9 × 10−6 𝑚4

𝑤0 = 20 𝑘𝑁⁄𝑚

Figure 1: A simply supported beam

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]

States the problems and objectives clearly and


Does not identify the problems and objectives.
identifies underlying issues. Develops a clear
Does not develop a coherent plan to solve the
and concise plan to solve the problem, offers
problem
alternative strategies
*Please make sure it is defined as a problem statement and not a question.
METHOD 1

2. Solve the ODE problem using Matlab/Octave. Display a snapshot of the .m file.

1. Shooting Method:
[CO4: 3 MARKS]

Excellent use of white space. Creatively


Does not develop a coherent plan to solve
organized work. Excellent use of variables
the problem
and constants. No magic numbers.
3. Illustrate your findings and conclude your observation from the graph.

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]

Excellent use of white space. Creatively


Does not develop a coherent plan to solve the
organized work. Excellent use of variables and
problem
constants. No magic numbers.
5. Illustrate your findings and conclude your observation from the graph.

Figure 3: Graph of Deflection vs Length

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);

%first & second assumption


zVal=[0.005,0.009];

%true value of y
y(4,:)=0.000003751.*x.*(1792-160.*x.^2+3.*x.^4);
y(4,node)=0;

%variable to hold new value of z


zNew=[0,0,0];

%variable to hold new value of y


yNew=[0,0,0];
fprintf("Shooting Method\n\n");
fprintf("Euler's method\n");
fprintf("Initial value:\n");
fprintf("x(0)=%.2f\ny(0)=%.2f\n",x(1),y(1,1));
fprintf("Guessed z value: %.2f and %.2f\n\n",zVal(1),zVal(2));
%Euler Method%
for i=1:3
if(i<=2)
z(1)=zVal(i);
fprintf("\nusing guess of z=%.2f\n",z(1));
else
z(1)=zVal(1)+(zVal(2)-zVal(1))*(y(4,node-1)-yNew(1))/(yNew(2)-yNew(1));
fprintf("\nInterpolating previous z value to obtain new z value\n");
fprintf("using interpolated z value=%f\n",z(1));
end

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);

%we know that y0=0 and y4=0%


%thus,coeff of y0 at node 1 and yn at last node is 1%
fdm(1,1)=1;
fdm(node,node)=1;

%RHS%
d2y=@(x) (0.0002504*x^3-0.003601*x)*h^2;

fprintf("Finite Difference Method\n");

fprintf("\nKnown Boundary Condition:");

fprintf("\nat x=%0.2fm, deflection is %0.2fm",x(1),y(1));

fprintf("\nat x=%0.2fm, deflection is %0.2fm",x(node),y(node));

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

fprintf("\nArrange the node's equation into matrix\n");

fdm

fprintf("\n\n");

%Naive Gauss Elimination Method%


%For forward substitution%
for i=1:node
fdm(i,:)=fdm(i,:)/fdm(i,i);

for j=i+1:node
fdm(j,:)=fdm(j,:)-fdm(i,:)*fdm(j,i);
end
end

%For back substitution method 2%


for i=node-1:-1:2
y(i)=fdm(i,node+1);

k=0;
for j=node-1:-1:i
y(i)=y(i)-fdm(i,node-k)*y(j+1);
k=k+1;
end
end

fprintf("Perform Naive Gauss Elimination Method\n");


fprintf("Naive Gauss Elimination Method\n");

fdm

fprintf("\n\n");

fprintf("Deflection at each point\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)');

title('Graph of Deflection(m) Versus Length(m) of Finite Difference Method');


legend('Finite Difference Method', 'True Value');

[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.

Figure 4: Graph of True Value and the 2 Methods


Table 1: Table of True Error

Method True error, 𝜺𝒕 (%) when 𝒙 = 𝟑. 𝟐

1. Shooting Method 0.0056196 − 0.009675


=| | × 100%
0.0056196
= 72.17%

2. Finite-Difference Method 0.0056196 − 0.0052531


=| | × 100%
0.0056196
= 6.52%

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.

You might also like