0% found this document useful (0 votes)
269 views18 pages

Applied Numerical Methods Project

Applied Numerical Methods Project featuring the bisection method and newton raphson method to solve a beam problem, and the gaussian elimination and gauss-seidel method to solve a 1D tapered bar FEM problem.

Uploaded by

Daffa Sudiana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
269 views18 pages

Applied Numerical Methods Project

Applied Numerical Methods Project featuring the bisection method and newton raphson method to solve a beam problem, and the gaussian elimination and gauss-seidel method to solve a 1D tapered bar FEM problem.

Uploaded by

Daffa Sudiana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

1.

0 Introduction

1.1 Aim
The aim of this project is to implement the idea that real life scenarios that real-life
scenarios can be studied and observed by creating mathematical models and
computing the data to obtain results using MATLAB.

1.2 Background
Numerical analysis has been around ever since 1650 BC, the time where the Egyptian
Rhind papyrus was created. It describes a root finding method for solving a simple
equation. Ever since then, numerical analysis has been used and applied by many great
scientists, mathematicians & engineers throughout history, such as Archimedes, Isaac
Newton, and many more.
Following the advancements of science & technology in the 20th century, engineers use
numerical analysis as a means to obtain mathematical models for solid and fluid
mechanics. One of the most well known numerical methods that is widely used in the
engineering field is the Finite Element Method (FEM). This involves working with such
models involves approximating a complex, continuous surface, structure, or process by a
finite number of simple elements. Numerical analysis can be broken down into three
categories:
1. Numerical linear and non-linear Algebra
Many problems in applied mathematics involve solving systems of linear equations. They
can be solved directly or iteratively using a sequence of approximating solutions of
increasing accuracy, whereas non-linear problems are solved numerically by reducing them
to a sequence of linear problems.

2. Approximation Theory
This category includes the approximation of functions with simpler or more tractable
functions and methods based on using such approximations.
3. Solving Differential and Integral Equations

There are two types of methods of solving differential and integral equations. The first type
approximates the unknown function in the equation by a simpler function. The second type
works by approximating the derivatives and integrals in the equations.
1.3 Methods Used
• Bisection Method
The bisection method is used to find the roots of a polynomial equation. It
separates the interval and subdivides the interval in which the root of the
equation lies. The principle behind this method is the intermediate theorem for
continuous functions. It works by narrowing the gap between the positive and
negative intervals until it closes in on the correct answer. This method
narrows the gap by taking the average of the positive and negative intervals. It
is a simple method, and it is relatively slow. The bisection method is also
known as interval halving method, root-finding method, binary search method
or dichotomy method. ("Bisection Method - Definition, Procedure, and
Example", 2020)
• Newton Raphson Method
The Newton-Raphson method uses an iterative process to approach one root
of a function. The specific root that the process locates depends on the initial,
arbitrarily chosen x-value. The method was found by English mathematicians,
Isaac Newton and Joseph Raphson. ("Newton-Raphson Method", 2020)

• Gaussian Elimination
The fundamental idea is to add multiples of one equation to the others in order
to eliminate a variable and to continue this process until only one variable is
left. Once this final variable is determined, its value is substituted back into
the other equations in order to evaluate the remaining unknowns. The method
was found by German mathematician, Johann Carl Friedrich Gauss (1777-
1855). ("Gaussian Elimination", 2020)
• Gauss – Seidel Iterative Method
The Gauss-Seidel Method is an improved version of the Jacobi iteration
method, also known as the successive displacement method. This method was
founded by Johann Carl Friedrich Gauss (1777–1855) and Philipp Ludwig
von Seidel (1821–1896). The difference between the Gauss–Seidel and Jacobi
methods is that the Jacobi method uses the values obtained from the previous
step while the Gauss–Seidel method always applies the latest updated values
during the iterative procedures. (Yang, 2018)
1.4 Scope
This project will solely focus on numerical analysis of nonlinear equations and
simultaneous linear algebraic equations. For the nonlinear equations, a beam deflection
problem will be solved using two methods: Bisection method and Newton – Raphson
Method. For the simultaneous linear algebraic equations, a finite element method
problem will be solved using two methods: Gaussian elimination and Gauss - Seidel
Iteration method. For each method, the results will be compared to determine the
accuracy to the true value.
2.0 Methodology
2.1 Algorithm & Flowchart
2.1.1 Bisection Method
1. Find points a and b such that a < b and f(a)•f(b) < 0
𝑎+𝑏
2. Take the interval [a, b] and find the next value xo =
2

3. If f(x0) = 0 then x0 is an exact root, else if 𝑓(𝑎) ∙ 𝑓(𝑥0 ) < 0 then 𝑏 = 𝑥0 , else
if 𝑓(𝑥0 ) ∙ 𝑓(𝑏) < 0 then 𝑎 = 𝑥0 .
4. Repeat steps 2 & 3 until 𝑓(𝑥𝑖 ) = 0 or |𝑓(𝑥𝑖 )| ≤ 𝐴𝑐𝑐𝑢𝑟𝑎𝑐𝑦
Fig 2.1 Bisection Method Flowchart
2.1.2 Newton Raphson Method
1. Find points a and b such that a<b and f(a)⋅f(b)<0.
𝑎+𝑏
2. Take the interval [a, b] and find the next value 𝑥𝑜 =
2

3. Find 𝑓(𝑥0 ) and 𝑓′(𝑥0 )


𝑓′(𝑥0 )
4. x1 = x0 −
𝑓(𝑥0 )

5. If 𝑓(𝑥1 ) = 0 then 𝑥1 is an exact root, else 𝑥0 = 𝑥1


6. Repeat steps 2 to 4 until 𝑓(𝑥𝑖 ) = 0 or |𝑓(𝑥𝑖 )| ≤ 𝐴𝑐𝑐𝑢𝑟𝑎𝑐𝑦
Fig 2.2 Newton-Raphson Method Flowchart

2.1.3 Gaussian Elimination Method


1. To perform Gaussian elimination starting with the system of equations

2. Compose the "augmented matrix equation"

3. Here, the column vector in the variables X is carried along for labeling
the matrix rows.
Now, perform elementary row operations to put the augmented matrix
into the upper triangular form
4. Solve the equation of the th row for , then substitute back into the
equation of the (k-1)st row to
obtain a solution for Xk-1, etc., according to the formula

Fig 2.3 Basic Flowchart of Gaussian Elimination

2.1.4 Gauss-Seidel Iteration Method


1. Arrange given system of linear equations in diagonally dominant form
2. Read tolerable error (𝜀)
3. Convert the first equation in terms of first variable, second equation in
terms of second variable and so on.
4. Set initial guesses for x0, y0, and z0
5. Substitute the value of y0 and z0 from step 4 in the first equation
obtained from step 3 to calculate new value of x1. Use x1, z0, and u0
in second equation obtained from step 3 to calculate the new value of
y1. The same can be done to find new z1 and so on using x1, y1, and
u0
6. If |𝑥0 − 𝑥1| > 𝜀, |𝑦0 − 𝑦1| > 𝜀, and |𝑧0 − 𝑧1| > 𝜀, proceed to step 8
7. Set x0=x1, y0=y1, z0=z1 and go back to step 5
8. x1, y1, and z1 are the values

Fig 2.4 Gauss – Seidel Iteration Method Flowchart


3.0 Problem Statement
3.1 Beam Deflection Problem

Theoretical Solution:
𝛴𝑀𝐴 = 0
40 – 10 – B (6) = 0
B = 5 kN
𝛴𝐹𝑦 = 0
A = - 5 kN
𝑑2 𝑦
𝐸𝐼 = 𝑀 = 40 − 5𝑥
𝑑𝑥 2
𝑑𝑦 5𝑥 2
𝐸𝐼 = 40𝑥 − +4
𝑑𝑥 2
40𝑥 2 5𝑥 3
𝐸𝐼𝑦 = − + 𝐶1𝑥 + 𝐶2
2 6
At x=0, y=0
C2=0
At x=6m, y=0
40(6)2 5(6)3
0= − + 𝐶1(6)
2 6
𝐶1 = −90 𝑘𝑁𝑚2
𝑑𝑦 1
= (40𝑥 − 2.5𝑥 2 − 90)
𝑑𝑥 𝐸𝐼
𝑑𝑦
For maximum deflection =0
𝑑𝑥

40𝑥 − 2.5𝑥 2 − 90 = 0
x= 2.708 m
1 5
𝑦𝑚𝑎𝑥 = (20(2.708)2 − (2.708)3 − 90(2.708))
𝐸𝐼 6
𝐸𝐼 = 200𝑥109 𝑥39.9𝑥10−6
𝑦𝑚𝑎𝑥 = −14.2𝑚𝑚

For this beam problem, the point (x) of maximum deflection can be found using the
Bisection and Newton-Raphson method. The iteration process will be done using
codes that correspond with the methods, written in MATLAB. The iterations will also
be presented for comparison to the value found using the theoretical solution.

3.1.1 Bisection Method MATLAB Code


clc
clear all
close all

y = @(x) -2.5*x^2 + 40*x - 90;


x1 = 2.5;
x2 = 3.0;
if y(x1)*y(x2) > 0
fprintf('No roots exist within the given interval\n')
return
end
if y(x1) == 0
fprintf('x1 is one of the roots\n')
return
elseif y(x2) == 0
fprintf('x1 is one of the roots\n')
return
end

fprintf('Iteration x1 x2 xh y(x1) y(x2)


y(xh)\n');
for i = 1:100
xh = (x1+x2)/2; %bisection
if y(x1)*y(xh) < 0
x2 = xh;
else
x1 = xh;
end
fprintf('%d %f %f %f %f %f
%f\n',i,x1,x2,xh,y(x1),y(x2),y(xh));
if abs(y(x1)) < 1.0E-6
break
end

end
fprintf('The root is: %f\nThe number of bisections: %d\n',x1,i)

3.1.2 Bisection Method Iteration Results


Iteration x1 x2 xh y(x1) y(x2) y(xh)
1 2.500000 2.750000 2.750000 -5.625000 1.093750 1.093750
2 2.625000 2.750000 2.625000 -2.226563 1.093750 -2.226563
3 2.687500 2.750000 2.687500 -0.556641 1.093750 -0.556641
4 2.687500 2.718750 2.718750 -0.556641 0.270996 0.270996
5 2.703125 2.718750 2.703125 -0.142212 0.270996 -0.142212
6 2.703125 2.710938 2.710938 -0.142212 0.064545 0.064545
7 2.707031 2.710938 2.707031 -0.038795 0.064545 -0.038795
8 2.707031 2.708984 2.708984 -0.038795 0.012884 0.012884
9 2.708008 2.708984 2.708008 -0.012953 0.012884 -0.012953
10 2.708496 2.708984 2.708496 -0.000034 0.012884 -0.000034
11 2.708496 2.708740 2.708740 -0.000034 0.006425 0.006425
12 2.708496 2.708618 2.708618 -0.000034 0.003196 0.003196
13 2.708496 2.708557 2.708557 -0.000034 0.001581 0.001581
14 2.708496 2.708527 2.708527 -0.000034 0.000773 0.000773
15 2.708496 2.708511 2.708511 -0.000034 0.000370 0.000370
16 2.708496 2.708504 2.708504 -0.000034 0.000168 0.000168
17 2.708496 2.708500 2.708500 -0.000034 0.000067 0.000067
18 2.708496 2.708498 2.708498 -0.000034 0.000016 0.000016
19 2.708497 2.708498 2.708497 -0.000009 0.000016 -0.000009
20 2.708497 2.708498 2.708498 -0.000009 0.000004 0.000004
21 2.708497 2.708498 2.708497 -0.000002 0.000004 -0.000002
22 2.708497 2.708497 2.708497 -0.000002 0.000001 0.000001
23 2.708497 2.708497 2.708497 -0.000001 0.000001 -0.000001
The root is: 2.708497
The number of bisections: 23
3.1.3 Newton Raphson Method MATLAB Code
clc
clear all
close all

x0=1;
maxIter = 50;
tolX = 1e-4;

x = x0;
xold = x0;
fprintf('Iteration x f df f/df\n')
for i = 1:maxIter
f = -2.5*x^2 + 40*x - 90;
df = -5*x + 40;
div = f/df;
x = x - f/df;
err(i) = abs(x-xold);
xold = x;
fprintf('%f %f %f %f %f\n',i,x,f,df,div);
if (err(i)<tolX)
break;
end

end
fprintf('The Root is: %f\nNumber of Iterations: %f\nError:
%f\n',xold,i,err(i));

3.1.4 Newton Raphson Methods Iterations


Iteration x f df f/df
1.000000 2.500000 -52.500000 35.000000 -1.500000
2.000000 2.704545 -5.625000 27.500000 -0.204545
3.000000 2.708496 -0.104597 26.477273 -0.003950
4.000000 2.708497 -0.000039 26.457520 -0.000001
The Root is: 2.708497
Number of Iterations: 4.000000
Error: 0.000001
3.2 Finite Element Method Problem (1D Bar)

A tapered bar of a circular cross section is given as below. The length of the bar is 1 m and the
radius varies as r(x) = 0.050 − 0.040x where r and x are in meters. The Young’s modulus for the
material is given as 100 MPa with both ends of the bar fixed and a point load of 10 kN being
applied at the centre of the bar. Set up the stiffness matrix, load and displacement vectors using
four bar elements with equal length. (Note: averaged element cross section area is assumed to be
�𝐴𝑖 𝐴𝑗 = 𝜋𝑟𝑖 𝑟𝑗 )
Solution:
0.25 m
0.25 m
0.25 m 0.25 m
10 kN

Q1,F1,R1 1 Q2,F2,R2 2 Q3,F3,R3 3 Q4,F4,R4 4 Q5,F5,R5

1 2 3 4 5
r1=0.05, r2=0.04, r3=0.03, r4=0.02, r5=0.01

𝐴1 = 𝜋(0.05)(0.04) = 2𝑥10−3 𝜋 𝑚2

𝐴2 = 𝜋(0.04)(0.03) = 1.2𝑥10−3 𝜋 𝑚2

𝐴3 = 𝜋(0.03)(0.02) = 6𝑥10−4 𝜋 𝑚2

𝐴4 = 𝜋(0.02)(0.01) = 2𝑥10−4 𝜋 𝑚2
100𝑥106 𝑥2𝑥10−3 𝜋 1 −1
K1= � �
0.25 −1 1

100𝑥106 𝑥1.2𝑥10−3 𝜋 1 −1
K2= � �
0.25 −1 1

100𝑥106 𝑥6𝑥10−4 𝜋 1 −1
K3= � �
0.25 −1 1

100𝑥106 𝑥2𝑥10−4 𝜋 1 −1
K4= � �
0.25 −1 1

2 −2 0 0 0
⎡−2 3.2 −1.2
−4 0 0 ⎤
10𝑥10 𝜋 ⎢ ⎥
[𝐾] = 0 −1.2 1.8 −0.6 0 ⎥
0.25 ⎢
⎢0 0 −0.6 0.8 −0.2⎥
⎣0 0 0 −0.2 0.2 ⎦

{𝑅} + {𝐹} = [𝐾]{𝑄}

𝑅1 0 2 −2 0 0 0 0
⎧ ⎫ ⎧ ⎫ ⎡ ⎤ ⎧ ⎫
⎪ 0 ⎪ ⎪ 0 ⎪ 10𝑥10−4 𝜋 ⎢−2 3.2 −1.2 0 0 ⎪𝑄2⎪

0 + 10000 = 0.25 ⎢ 0 −1.2 1.8 −0.6 0 ⎥ 𝑄3
⎨0⎬ ⎨ 0 ⎬ ⎢0 0 −0.6 0.8 −0.2⎥ ⎨ ⎬
⎪ ⎪ ⎪ ⎪ ⎪𝑄4⎪
⎩𝑅5⎭ ⎩ 0 ⎭ ⎣0 0 0 −0.2 0.2 ⎦ ⎩ 0 ⎭

0 40.2124 −15.0796 0 𝑄2
�10000� = �−15.0796 22.6195 −7.5398� �𝑄3�
0 0 −7.5398 10.0531 𝑄4

The method for determining the nodal displacements can be done using Gaussian Elimination
and Gauss-Seidel Iteration Method.

3.2.1 Gaussian Elimination MATLAB Code


clc
clear
%The reduced global load vector in matrix form
K = 100*[40.2124 -15.0796 0; -15.0796 22.6195 -7.5398; 0 -7.3598 10.0531];
F = [0 10000 0]';

%%Solving using Gaussian Elimination


%Get augmented matrix
KF = [K, F];
%With A(1,1) as pivot element
alpha = KF(2,1)/KF(1,1);
KF(2,:) = KF(2,:) - alpha*KF(1,:);
alpha = K(3,1)/K(1,1);
KF(3,:) = KF(3,:) - alpha*KF(1,:);

%With A(2,2) as pivot element


alpha = KF(3,2)/KF(2,2);
KF(3,:) = KF(3,:) - alpha*KF(2,:);

%Back-Substitution
Q = zeros(3,1);
Q(3) = KF(3,end)/KF(3,3);
Q(2) = ( KF(2,end)-KF(2,3)*Q(3) ) / KF(2,2);
Q(1) = ( KF(1,end)-KF(1,2)*Q(2)-KF(1,3)*Q(3) ) / KF(1,1);

disp('The displacement at each node is')


disp(Q)

3.2.2 Gaussian Elimination Result


The displacement at each node is
3.2766
8.7376
6.3967
(Nodal displacements are in mm)

3.2.3 Gauss – Seidel Iteration Method MATLAB Code


clc
clear
%The reduced global load vector in matrix form
K = 100*[40.2124 -15.0796 0; -15.0796 22.6195 -7.5398; 0 -7.3598 10.0531];
F = [0 10000 0]';
[m,n] = size(K);

N = 25;
err = 0.01;

Q = [0 0 0];
QQ(1,:) = Q;

fprintf('Iteration x1 x2 x3\n');
for k = 2 : N
for i = 1:n
s =0;
for j = 1:n
if j ~= i
s = s + K(i,j) * Q(j);
end
end
Q(i) = (1/K(i,i))*(F(i) - s);
end
disp([' ' num2str(k) ' ' num2str(Q) ' ']);
QQ(k,:) = Q; kk = k;
Err = abs(max(QQ(k,:)-QQ(k-1,:))); if Err < err, break; end
end
disp(['The Roots are [ ' num2str(Q) '], with accuracy: ' num2str(Err) ' ,and
' num2str(kk),' iterations'])

3.2.4 Gauss – Seidel Iteration Method Results


Iteration x1 x2 x3
2 0 4.421 3.2366
3 1.6579 6.605 4.8355
4 2.4769 7.684 5.6254
5 2.8815 8.2171 6.0157
6 3.0814 8.4804 6.2085
7 3.1802 8.6105 6.3037
8 3.2289 8.6748 6.3508
9 3.253 8.7066 6.374
10 3.2649 8.7222 6.3855
11 3.2708 8.73 6.3912
The Roots are [ 3.2708 8.73 6.3912], with accuracy: 0.0077496
,and 11 iterations
(Nodal displacements are in mm)
4.0 Discussion
The project was conducted with the aim of determining the roots of nonlinear equations and
simultaneous linear algebraic equations using MATLAB. As previously mentioned, roots of
the nonlinear equations were to be determined using the bisection method and the Newton-
Raphson Iterative method, whereas the simultaneous linear algebraic equations were to be
determined using Gaussian Elimination and the Gauss-Seidel Iterative method. Then, the
results would be compared based on the accuracy to the true value.
The first task was to determine the point along the length of a beam where it experiences the
largest deflection. The true value was first determined theoretically, at which the point was
found to be x = 2.708 m. When the bisection method was used to find the point of maximum
deflection, it was found to be x = 2.708497 m, with 23 iterations. The same exact value was
yielded when the Newton – Raphson iterative method, the only difference is that it only four
iterations, which is much faster and efficient. Therefore in order to save more time for
calculations, the Newton-Raphson method can be used to determine the point of maximum
deflection numerically.
The second task was to determine the nodal displacements of a tapered bar subjected to a
load of 10kN using the finite element method. The bar was divided into four discrete
elements with 5 nodes resulting in a 5x5 matrix. The first and the last node is stationary,
therefore the second, third and fourth node will be displaced. From there, the simultaneous
linear algebraic equations in order to find the nodal displacements could be determined. The
methods used for solving them were the Gaussian Elimination and Gass-Seidel Iterative
method. The nodal displacements were found to be [3.2766 8.7376 6.3967] mm using
Gaussian Elimination. When the Gauss-Seidel iterative method was used, the nodal
displacements were found to be [3.2708 8.7300 6.3912] mm with 11 iterations. The
percentage difference for each node is 0.177%, 0.087%, and 0.086%, respectively, meaning
they are still within the accuracy range.
For more accurate and faster numerical analysis, the initial guess of the value should be close
as possible to the true value when performing numerical analysis using the bisection and the
Newton-Raphson method. This will reduce the number of iterations and hence making it
more efficient. In order to find more accurate nodal displacements for the finite element
problem, the element can be divided into more discrete individual elements for greater
accuracy.

5.0 Conclusion

In conclusion, the objective of this project was to implement MATLAB coding skills in solving
Real-Life Based problems with the aid of Numerical Methods. The problems that were
introduced were a beam deflection problem and 1-D Bar finite element problem. The problems
involved a solving non-linear equation and a system of linear algebraic equations, respectively.
For each problem, there were two numerical methods which were used for numerical analysis.
The first problem was analyzed using the bisection method and the Newton-Raphson method
which both yielded the same exact value very accurate to the true value. The only difference is
that the Newton-Raphson method took lesser iterations making it more efficient. The second
problem was analyzed using Gaussian Elimination and the Gauss-Seidel Iteration method in
which the roots were found with 11 iterations. The values yielded between the two methods were
precise and within the accuracy range. Hence, the aim of this project of implementing MATLAB
coding with the aid of Numerical Methods was achieved.
6.0 References

Shah, P. (2020). Bisection method Algorithm & Example-1. Retrieved 16 May 2020, from
https://atozmath.com/example/CONM/Bisection.aspx?he=e&q=bi

Bisection Method Algorithm and Flowchart | Code with C. (2020). Retrieved 16 May 2020, from
https://www.codewithc.com/bisection-method-algorithm-flowchart/

Gaussian Elimination. (2020). Retrieved 16 May 2020, from


https://www.cs.rutgers.edu/~venugopa/parallel_summer2012/ge.html#algo

Gauss Seidel Iteration Method Algorithm. (2020). Retrieved 16 May 2020, from
https://www.codesansar.com/numerical-methods/gauss-seidel-iteration-algorithm.htm

Bisection Method - Definition, Procedure, and Example. (2020). Retrieved 25 May 2020, from
https://byjus.com/maths/bisection-method/

Newton-Raphson Method. (2020). Retrieved 25 May 2020, from


http://www.shodor.org/unchem/math/newton/

Gaussian Elimination. (2020). Retrieved 25 May 2020, from https://www.cliffsnotes.com/study-


guides/algebra/linear-algebra/linear-systems/gaussian-elimination

Yang, K. (2018). Stepping Through Finite Element Analysis. Basic Finite Element Method As
Applied To Injury Biomechanics, 281-308. doi: 10.1016/b978-0-12-809831-8.00007-6

You might also like