Professional Documents
Culture Documents
location
CES 513- ONLINE LAB LEARNING SESSION
Week 5 (13/4/2020 – 17/4/2020)
(SYAHRUL FITHRY BIN SENIN)
SENIOR LECTURER
FACULTY OF CIVIL ENGINEERING
UiTM PULAU PINANG
10/4/2020 Prepared by SFS 2020 1
Lesson Learning Outcomes
• to write correct and runnable MATLAB script to program the Bisection
Method algorithm (CO2:PO5)
• to write correct and runnable MATLAB script to program the Newton-
Raphson Method (CO2:PO5)
• to plot the graph of equation for estimation of nonlinear equation
solution (CO2:PO5)
• Example1
The dimension of the open channel can be determined by solving equation Q above and using non-linear
equation root solving
10/4/2020 Prepared by SFS 2020 4
Example 2
• To solve the following nonlinear equation of bending moment, M(x),
of a cantilever beam under triangle load,
𝟓𝟓
𝑴𝑴 𝒙𝒙 = 𝟏𝟏𝟏𝟏𝟏𝟏𝟏𝟏 − 𝒙𝒙𝟑𝟑
𝟔𝟔
What is the value of distance, x, that will give the bending moment to be 220 lb-ft?
M(x) – 220 = 0
𝟓𝟓 𝟑𝟑
𝟏𝟏𝟏𝟏𝟏𝟏𝟏𝟏 − 𝒙𝒙 − 𝟐𝟐𝟐𝟐𝟐𝟐 = 𝟎𝟎
𝟔𝟔
10/4/2020 Prepared by SFS 2020 6
𝟓𝟓 𝟑𝟑
𝒇𝒇 𝒙𝒙 = 𝟏𝟏𝟏𝟏𝟏𝟏𝟏𝟏 − 𝒙𝒙 − 𝟐𝟐𝟐𝟐𝟐𝟐
Strategy INITIAL GUESS
𝟔𝟔
xl Xu F(xl) F(XU)
0 1 +VE
0 1.5 +ve
0 2 -ve
ea = 100;
es = 1;
xL = 0;
xU = 2;
% xL = the lower limit');
% xU = the upper limit');
sign1 = f(xL)*f(xU);
end
disp(' ')
disp( ' iter xL xU xm ea')
disp( '________________________________________________')
disp(' ‘)
iter = 0;
xm =10/4/2020
0.5*(xL+xU); Prepared by SFS 2020 17
while ea > es
sign2 = f(xL)*f(xm);
if sign2 < 0
xmold = xm;
xU = xm;
xL = xL;
ea = ea;
else
ea = abs((xmnew-xmold)/xmold)*100;
end
end
fprintf(‘%i %3f %3f %3f %3f \n’, iter, xL, xU,xm, ea)
end
• Compute the absolute relative error, ea, using the following equation
ea= (xn+1 – xn)/xn+1 x 100
• If ea < es, estimate the new guess root, x2 from Eqn (1) and repeat this
process until ea < es
• Stop AND DISPLAY THE root values and its iteration number
10/4/2020 Prepared by SFS 2020 25
Newton-Raphson Method Using Octave/MATLAB
x0 =10;
es = 1;
ea = 100;
x = x0;
iter = 0;
disp(' ')
fprintf('The root of this equation is %5f by iteration of %i with error of %3f \n',x,iter,ea)