Você está na página 1de 33

TAKE HOME EXAM

AE2201 Analisis Teknik dan Metode Numerik

Oleh:

Alfarizki Qodri

13617030

Tanggal Pengumpulan : 25 November 2019

PROGRAM STUDI TEKNIK DIRGANTARA

FAKULTAS TEKNIK MESIN DAN DIRGANTARA

INSTITUT TEKNOLOGI BANDUNG


2019
Alfarizki Qodri - 13617030

“I hereby declare that all answers in the exam are from my independent work. I did not commit
or facilitate any improper conduct during this exam. If i am proven to be in violation, I am
ready to accept the consequences in accordance with the applicable regulations”

(Alfarizki Qodri)

1. The velocity of a falling parachutist is defined as the following:


𝑔𝑚 𝑐
𝑣= (1 − 𝑒 −(𝑚)𝑡 )
𝑐
Where the gravity g = 9.8 1m/s2. Compute the following:
a) For a parachutist with a drag coefficient of c = 15 kg/s and the velocity v = 36 m/s at t
= 10s. Compute the mass m of the parachutist using fixed point iteration and newton-
raphson methods with the relative error e = 0.1% or lower. Compare both methods in
terms of the number of iterations required.

Answer:

By using fixed point iteration,

Rearrange the function f(x) = 0 so that x is on the left-hand side of the equation:

x = g (x) ……………………………………………………………………………….(1.1)

From the given function, we can arrange that into,

𝑣𝑐
𝑚= −(
𝑐
)𝑡
. …………………………………………………………………..(1.2)
𝑔(1−𝑒 𝑚 )

The utility of Eq (1.1) is that it provides a formula to predict a new value of x as a founction
of an old value of x. Thus, given an initial guess at the root x i. Eq. (1.1) can be used to
compute a new estimate xi+1 as expressed by the iterative formula
xi+1 = g(xi) ..…………………………………………………………………………….(1.3)

Subtitute the known parameter v, c, g, and t into Eq (1.2). Then it will be a function that can
be used in the program to find mass by using fixed point iteration.

2
Alfarizki Qodri - 13617030

3
Alfarizki Qodri - 13617030

Here is the Matlab program.

clear all
clc

syms x;
tol = 1e-3;

x0 = 0;
x = x0;
y = x0;

for i = 1:10
x = (36*15/9.81)/(1-exp(-150/x));
error = abs(x-y);
y=x;

if (error<tol)
break
end
end
fprintf('Total Iteration')
i
x
The result of the program will show the total iteration and the result of x (mass) which
gives the total iteration equal to 8 to have a result less than the wanted error. And the mass
m of the parachutist using fixed point iteration is 59.9592 kg
For the full iteration,
Iteration xi Error[%]
0 0
1 55.0459 100
2 58.9070 386.11
3 59.7263 81.93
4 59.9073 18.11
5 59.9477 4.03
6 59.9567 0.90
7 59.9587 0.20
8 59.9592 0.04489

By using the Newton-Raphson Method,


It can be derived on the basis of this geometrical interpretation (based on Taylor series).
The first derivative at x is equivalent to the slope:
𝑓(𝑥𝑖 )−0
𝑓 ′ (𝑥𝑖 ) = ..…………………………………………………………….…….(1.4)
𝑥𝑖 −𝑥𝑖+1

Which can be rearranged to yield


𝑓(𝑥 )
𝑥𝑖+1 = 𝑥𝑖 − 𝑓′(𝑥𝑖 )..…………………………………………………………….…….,,,(1.5)
𝑖

4
Alfarizki Qodri - 13617030

So, before continue to the program, first rearrange the given equation into,
𝑣𝑐
𝑓(𝑚) = 𝑚 − −(
𝑐
)𝑡
= 0 ………………………………..…………………(1.6)
𝑔(1−𝑒 𝑚 )

Then, substitute the known parameter into that equation. The function then will be used in
the Matlab program.

5
Alfarizki Qodri - 13617030

clear all
clc

syms x;
tol = 1e-3;

fun = x - ((36*15/9.81)/(1-exp(-150/x)));
f = inline(fun);

z = diff(f(x));
f1 = inline(z);

x0 = 1;
x = x0;
y = x0;

for i = 1:10
x=y-(f(x)/f1(x));
error = abs(x-y);
y=x;

if (error<tol)
break
end
end
fprintf('Total Iteration')
i
x
The result of the program will show the total iteration and the result of x (mass) which
gives the total iteration equal to 4 to have a result less than the wanted error. And the mass
m of the parachutist using the Newton-Raphson Method is 59.9593 kg
For full iteration,
Iteration xi Error[%]
0 1
1 55.0459 100
2 59.8999 485.4
3 59.9593 5.94
4 59.9593 0.0008027

Notice that the error at each iteration decreases much faster than it does in simple
fixed-point iteration. So the iteration that used in this method is lesser than the one
in simple fixed-point iteration.

6
Alfarizki Qodri - 13617030

b) If the mass of the parachutist m = 82kg, determine the drag coefficient c when the
velocity v = 36 m/s after 4 s free fall. Use the bisection and false position methods with
the initial guesses of c between 3 and 5 kg/s. Perform iteration until the relative error
falls below 2%. Compare both methods in terms of the number of iterations required.

Answer:
Using Bisection Method,
One type of incremental search method in which the interval is always divided in half. If
a function changes sign over an interval, the function value at the midpoint is evaluated.
The location of the root is then determined as lying at the midpoint of the subinterval
within which the sign change occurs. The process is repeated to obtain refined estimates.
Step 1
Choose lower xl and upper xu guesses for the root such that the function changes sign over
the interval. This can be checked by ensuring that f(xl)f(xu) < 0.
Step 2
An estimate of the root xr is determined by, xr = (xl + xu)/2
Step 3
Make the following evaluations to determine in which subinterval the root lies:
(a) if f(xl)f(xr) < 0, the root lies in the lower subinterval. Therefore, set x u = xr and return
to step 2.
(b) if f(xl)f(xr) > 0, the root lies in the upper subinterval. Therefore, set x l = xr and return
to step 2.
(c) if f(xl)f(xr) = 0, the root equals to xr, terminate the computation.

Before the concept run into the program, first rearrange the given equation into this:
𝑐
𝑔𝑚
𝑓(𝑐) = 𝑐 − (1 − 𝑒 −(𝑚)𝑡 ) = 0 ……………………………………….…………….(1.7)
𝑣

Then, substitute the known parameter into that equation. The function then will be used in
the Matlab program. And set lower x = 3, and upper x = 5.

7
Alfarizki Qodri - 13617030

x2

8
Alfarizki Qodri - 13617030

clear all
clc

x0 = 3
x1 = 5
tolerance = 0.02
f =@(x) x-((22.345-22.345*exp(-4*x/82)));

for i=1:10
x2 = (x0+x1)/2;
if f(x0)*f(x2)<0
x1 = x2;
else
x0 = x2;
end
if abs(f(x0)) < tolerance
break;
end
end
x2
i
The result of the program will show the total iteration and the result of x2 (c drag
coefficient) which gives the total iteration equal to 2 to have a result less than the wanted
error (2%). And the drag coefficient c of the parachutist using the Bisection Method is 3.5.
which gives error 0.71%.
Using False-position Method,
An alternative method that exploits this graphical insight is to join f(xl) and f(xu) by a
straight line. The intersection of this line with the x axis represents an improved estimate
of the root. The intersection of the straight line with the x axis can be estimated as
f(xl)/(xr – xl) = f(xu)/(xr – xu)
or estimate of the root xr can be solved for
𝑓(𝑥𝑢 )(𝑥𝑙 −𝑥𝑢 )
𝑥𝑟 = 𝑥𝑢 − ………………………………………………………………..(1.8)
𝑓(𝑥𝑙 )−𝑓(𝑥𝑢 )

By using the same steps as Bisection and using the rearrange function (1.7) to the program,

9
Alfarizki Qodri - 13617030

x2

10
Alfarizki Qodri - 13617030

clear all
clc
x0 = 3
x1 = 5
tolerance = 0.02
f =@(x) x-((22.345-22.345*exp(-4*x/82)));
for i=1:10
x2 = x1 - (f(x1)* (x1-x0)/(f(x1)-f(x0)))
c = f(x2)
absolute_c = abs(c);
if absolute_c < tolerance
break
end
if f(x0)*c <0
x1=x2;
continue
else
x0=x2;
continue
end
end
x2
i
The result of the program will show the total iteration and the result of x2 (c drag
coefficient) which gives the total iteration equal to 1 to have a result less than the wanted
error (2%). And the drag coefficient c of the parachutist using the Bisection Method is
3.4082 which gives error 1.4%
Note how the error for false position decreases much faster only in the 1st iteration
than for bisection. This is because of the more efficient scheme for root location in
the false-position method.

2. One of the solution strategy on the numerical method can also use the linear equation
solution, for example the eigen value and eigen vector to solve the vibration problems. The
finite difference method can also be used to solve the partial differential equation using
the system of linear equation. You ara asked to create a programming code to solve a
system of linear equation below:

a) The program should provide OPTIONS for numerical method solutions:


OPTION A: Using Gauss Elimination
OPTION B: Using Gauss-Seidel
b) Input data can be formulated in the form of how many equations you will be solving
and the corresponding coefficients, for example: X1 = 2, X2=4 . . . Xn = 7
c) Validate your programming code by using the above system of linear of quations.
d) Please explain any assumption used in the solution method.
11
Alfarizki Qodri - 13617030

Answer:
Gauss elimination, also known as row reduction, is an algorithm in linear algebra for
solving a system of linear equations.
To perform row reduction on a matrix, one uses a sequence of elementary row operations
to modify the matrix until the lower left-hand corner of the matrix is filled with zeros, as
much as possible. There are three types of elementary row operations:
a) Swapping two rows,
b) Multiplying a row by a nonzero number,
c) Adding a multiple of one row to another row.
Using these operations, a matrix can always be transformed into an upper triangular matrix.

The Gauss–Seidel method is an iterative technique for solving a square system of n linear
equations with unknown x:
Ax = b
It is defined by the iteration
L*x(k+1) = b – Ux(k),
Where x(k) is the kth approximation or iteration of x, x(k+1) is the next or k+1 iteration of x
and the matrix A is decomposed into a lower triangular component L* and a upper
triangular component U:
A = L* + U
The system of linear equations may be rewritten as:
L*x = b – Ux
The Gauss-Seidel method now solves the left hand side of this expression for x, using
previous value of x on the right hand side. Analytically, this may be written as:
x(k+1) = L*(b – Ux(k))
The procedure is generally continued until the changes made by an iteration are below
some tolerance.

Using Matlab, the following code is computed.


clear all
clc

n = input('How many equations you want to solve? ');


A = zeros(n,n);
B = zeros(n,1);
C = zeros(n,n+1);
%Create Matrix A
disp(['Matrix A']);
for i=1:n
disp(['For equation ',num2str(i),':']);
for j=1:n
A(i,j) = input(['Coefficient X',num2str(j),': ']);
end
end

%Create Matrix B
disp(['Matrix B']);
for i=1:n
disp(['For equation ',num2str(i),':']);
B(i,1) = input(['Result for Equation ',num2str(i),':']);

12
Alfarizki Qodri - 13617030

end
%Display Matrices From The Input
A
B
%Choosing from two methods available
disp(['For Gauss Elimination Method, Type [1]']);
disp(['For Gauss-Seidel Method, Type [2]']);
m = input('Method to solve the system: ');

%Both Method Code


if m == 1 %Gauss Elemination Method is Chose
%Combine Matrix A and B
for i =1:n
for j=1:n
C(i,j) = A(i,j);
end
end
for i=1:n
C(i,n+1)=B(i,1);
end
C
[m,n] = size(C);

for i = 1:m-1
for k = 2:m
if C(i,i) == 0
t = C(i,:);
C(i,:) = C(k,:);
C(k,:) = t;
end
end

for j = i+1:m
C(j,:) = C(j,:) - C(i,:)*(C(j,i)/C(i,i));
end
end
k = 0;
X=zeros(1,m);
for s=m:-1:1
c=0;
for k=2:m
c=c+C(s,k)*X(k);
end
X(s)=(C(s,n)-c)/C(s,s);
end
disp('Gauss Elimination Method:');
C
X
else if m == 2 %Gauss-Seidel Method
[m,n] = size(A);
N =input('Number of Iteration :'); %number of iterations
err = input('Error: '); %Result Accuracy
x = zeros(n,1);
xx(1,:) = x;

for k = 2:N
for i = 1:n
s = 0;
for j = 1:n

13
Alfarizki Qodri - 13617030

if j ~= i
s = s + A(i,j) * x(j);
end
end
x(i) = (1/A(i,i))*(B(i)-s);
end
xx(k,:) = x;
kk = k;
Err = abs(max(xx(k,:)-xx(k-1,:)));
if Err < err
break;
end

end
disp(['The Solution will be']);
x
disp(['Error :' num2str(Err)]);
disp(['No. Iteration :' num2str(kk)]);
end
end

To validate the program, input the given matrices to the program.


The output of the program is as follows:
For the Gauss Elimination Method
How many equations you want to solve? 5
Matrix A
For equation 1:
Coefficient X1: 8
Coefficient X2: -2
Coefficient X3: -1
Coefficient X4: 0
Coefficient X5: 0
For equation 2:
Coefficient X1: -2
Coefficient X2: 9
Coefficient X3: -4
Coefficient X4: -1
Coefficient X5: 0
For equation 3:
Coefficient X1: -1
Coefficient X2: -3
Coefficient X3: 7
Coefficient X4: -1
Coefficient X5: -2
For equation 4:
Coefficient X1: 0
Coefficient X2: -4
Coefficient X3: -2
Coefficient X4: 12
Coefficient X5: -5
For equation 5:
Coefficient X1: 0

14
Alfarizki Qodri - 13617030

Coefficient X2: 0
Coefficient X3: -7
Coefficient X4: -3
Coefficient X5: 15
Matrix B
For equation 1:
Result for Equation 1:5
For equation 2:
Result for Equation 2:2
For equation 3:
Result for Equation 3:0
For equation 4:
Result for Equation 4:1
For equation 5:
Result for Equation 5:5

A=

8 -2 -1 0 0
-2 9 -4 -1 0
-1 -3 7 -1 -2
0 -4 -2 12 -5
0 0 -7 -3 15

B=

5
2
0
1
5

For Gauss Elimination Method, Type [1]


For Gauss-Seidel Method, Type [2]
Method to solve the system: 1

C=

8 -2 -1 0 0 5
-2 9 -4 -1 0 2
-1 -3 7 -1 -2 0
0 -4 -2 12 -5 1
0 0 -7 -3 15 5

Gauss Elimination Method:

C=

8.0000 -2.0000 -1.0000 0 0 5.0000

15
Alfarizki Qodri - 13617030

0 8.5000 -4.2500 -1.0000 0 3.2500


0 0 5.2500 -1.3824 -2.0000 1.8676
0 0 0 10.4762 -6.5238 3.9524
0 0 0 0 9.3174 9.3174

X=

1.0000 1.0000 1.0000 1.0000 1.0000

>>

For the Gauss-Seidel Method


Method to solve the system: 2
Number of Iteration :30
Error: 0
The Solution will be

x=

1.0000
1.0000
1.0000
1.0000
1.0000

Error :1.5839e-06
No. Iteration :30

From the output, the result of Gauss and Gauss-Seidel elimination method is MATCH.
It is assumed that this programming code is applicable for the system of linear equations
(consists of five equations).

3. Solve the following problem over the interval from x = 0 to 5 using a step size of 0.5. The
initial conditions are y(0) = 4 and y’(0) = 0
𝑑2𝑦 𝑑𝑦
2
+ 0.6 + 8𝑦 = 0
𝑑𝑥 𝑑𝑥
a) Find the analytical solution

Answer:
y” + 0.6y’ + 8y = 0

The characteristic equation is s2 + 0.6s + 8 = 0


−0.6±√0.62 −(4)(1)(8)
𝑠1,2 = or
2

16
Alfarizki Qodri - 13617030

−3±√791𝑖
𝑠1,2 =
10
So, it will get the total solution,
√791 √791
𝑦 = 𝑒 −0.3𝑥 (𝑐1 cos ( 𝑥) + 𝑐2 cos ( 𝑥))
10 10
To find the c1 and c2, substitute the solution with the initial condition:
For y(0) = 4,
C1 = 4

Derivate the total solution, then substitute the y’(0) = 0, it will gives
√791
−0.3𝑐1 + 𝑐 =0
10 2
Then, substitute the known C1, so…
C2 = 12/√𝟕𝟗𝟏= 0.42667

Subtitute back the known C1 and C2 into the total solution,


√791 12 √791
𝑦 = 𝑒 −0.3𝑥 (4 cos ( 𝑥) + √791 cos ( 𝑥))………………………………………(3.1)
10 10

b) Solve numerically with Euler Method


Answer:
This method estimate can be substituted into Equation,
𝑦𝑖+1 = 𝑦𝑖 + 𝑓(𝑥𝑖 , 𝑦𝑖 )ℎ…………………………………………………………….......(3.2)

We first need to write our equation as a system of two first order equations, let
𝑑𝑦
𝑧=
𝑑𝑥
Now we have
𝑑𝑧
+ 0.6𝑧 + 8𝑦 = 0
𝑑𝑥
And our system is now
𝑑𝑦
=𝑧
𝑑𝑥
𝑑𝑧
= −0.6𝑧 − 8𝑦
𝑑𝑥
With y(0) = 4 and z(0) = 0 on [0.5] with h = 0.5.
Then do the iteration by using Eq (3.2) as
𝑥𝑖+1 = 𝑖. ℎ
𝑦𝑖+1 = 𝑦𝑖 + 𝑧𝑖 ℎ
𝑧𝑖+1 = 𝑧𝑖 + (𝑑𝑧𝑖 /𝑑𝑥)ℎ

17
Alfarizki Qodri - 13617030

18
Alfarizki Qodri - 13617030

Then the Matlab program will be,


clear all
clc

x(1)=0;
y(1)=4;
z(1)=0;

for i=1:10
x(i+1)=i*0.5;
dy=z(i);
dz=-0.6*z(i)-8*y(i);
y(i+1)=y(i)+(dy*0.5);
z(i+1)=z(i)+(dz*0.5);
end

step = [0:10]';
x_i=x';
y_i=y';
z_i=z';

table(step, x_i, y_i, z_i)

Then, it will give the x, y, z results in Table


Step x_i y_i z_i
0 0 4 0
1 0.5 4 -16
2 1 -4 -27.2
3 1.5 -17.6 -3.04
4 2 -19.12 68.272
5 2.5 15.016 124.27
6 3 77.151 26.925
7 3.5 90.614 -289.76
8 4 -54.265 -565.29
9 4.5 -336.91 -178.64
10 5 -426.23 1222.6

c) Solve numerically with Heun Method


Answer:
Recall in Euler’s method, the slope at the beginning of an interval
𝑦′𝑖 = 𝑓(𝑥𝑖 , 𝑦𝑖 )
……………………………………………………………………………………….. (3.3)
is used to extrapolate linearly to 𝑦𝑖+1 :
0
𝑦𝑖+1 = 𝑦𝑖 + 𝑓(𝑥𝑖 , 𝑦𝑖 )ℎ
0
In Heun’s method the 𝑦𝑖+1 is not the final answer, but an intermediate prediction that called
predictor equation.
It provides an estimate of 𝑦𝑖+1 that allows the calculation of an estimated slope at the end
of interval:

19
Alfarizki Qodri - 13617030

′ 0
𝑦𝑖+1 = 𝑓(𝑥𝑖+1 , 𝑦𝑖+1 )………………………………………………………………….(3.4)
Thus, the Eq(3.3) and (3.4) can be combined to obtain an average slope. This average slope
is then used to extrapolate linearly from 𝑦𝑖 to 𝑦𝑖+1 using Euler’s method:
0
𝑓(𝑥𝑖 , 𝑦𝑖 ) + 𝑓(𝑥𝑖+1 , 𝑦𝑖+1 )
𝑦𝑖+1 = 𝑦𝑖 + ℎ
2
Which is called a corrector equation.

By doing the same step as explained in the Euler section,


Then do the iteration by using predictor-corrector equation.

20
Alfarizki Qodri - 13617030

clear all
clc

x(1)=0;
y(1)=4;
z(1)=0;

for i=1:10
x(i+1)=i*0.5;
k1(i) = (-8*y(i))-(0.6*z(i));
k2(i) = (-8*(y(i)+0.5))-(0.6*(z(i)+0.5));
z(i+1) = z(i) + ((k1(i)+k2(i))*0.5/2);
k3(i) = z(i);
k4(i) = z(i) + 0.5;
y(i+1) = y(i) + ((k3(i)+k4(i))*0.5/2);
end

step = [0:10]';
x_i=x';
y_i=y';
z_i=z';

table(step, x_i, y_i, z_i)

Then, it will give the x, y, z results in Table


Step x_i y_i z_i
0 0 4 0
1 0.5 4.125 -17.075
2 1 -4.2875 -29.528
3 1.5 -18.926 -4.5943
4 2 -21.098 71.414
5 2.5 14.734 133.31
6 3 81.513 33.306
7 3.5 98.291 -303.81
8 4 -53.49 -606.91
9 4.5 -356.82 -211.95
10 5 -462.67 1277.8

d) Solve numerically with Fourth Order Runge-Kutta Method


Answer:

The fourth-order Runge-Kutta method:


1
𝑦𝑖+1 = 𝑦𝑖 + (𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4 )ℎ………………………………………………(3.5)
6
By doing the same step as explained in the Euler section,
Then do the iteration by using Equation (3.5) as:

21
Alfarizki Qodri - 13617030

22
Alfarizki Qodri - 13617030

23
Alfarizki Qodri - 13617030

The Matlab program:


clear all
clc

x(1)=0;
y(1)=4;
z(1)=0;

for i=1:10
x(i+1)=i*0.5;
k11=z(i);
k12=-0.6*z(i)-8*y(i);
k21=z(i)+k12*0.5/2;
k22=-0.6*(z(i)+k12*0.5/2)-8*(y(i)+k11*0.5/2);
k31=z(i)+k22*0.5/2;
k32=-0.6*(z(i)+k22*0.5/2)-8*(y(i)+k21*0.5/2);
k41=z(i)+k32*0.5;
k42=-0.6*(z(i)+k32*0.5)-8*(y(i)+k31*0.5);
y(i+1)=y(i)+(k11+2*k21+2*k31+k41)*0.5/6;
z(i+1)=z(i)+(k12+2*k22+2*k32+k42)*0.5/6;
end

step = [0:10]';
x_i=x';
y_i=y';
z_i=z';

table(step, x_i, y_i, z_i)

Then, it will give the x, y, z results in Table


Step x_i y_i z_i
0 0 4 0
1 0.5 1.0367 -9.2887
2 1 -2.4276 -3.1969
3 1.5 -1.5571 5.3654
4 2 1.1539 4.0719
5 2.5 1.481 -2.3334
6 3 -0.29348 -3.6375
7 3.5 -1.1319 0.37231
8 4 -0.18529 2.6602
9 4.5 0.72415 0.65639
10 5 0.37821 -1.6258

e) Plot all solutions in the same graph.


By combining all the methods’ programs, then it will gives the plot:

24
Alfarizki Qodri - 13617030

Figure 3.1 (a) Plot all methods

Figure 3.1 (b) Plot all methods (zoom-in)

25
Alfarizki Qodri - 13617030

From Figure 3.1(a) we know that Euler method graph is similar to Heun method.
Then From figure 3.2(b) the exact solution is more similar to Runge-Kutta 4th Order
Method. It means that it more accurates using the RK 4 method than the other
method.

4. The basic elastic differential equation of the elastic curve for a uniformly loaded beam is
given as

Where E = the modulus of elasticity and I = the moment of inertia. Solve for the deflection
of the beam using the finite difference approach with dx = 2 m. The following parameters
values apply: E = 70 GPa, I = 800 m4, w = 1 kN/m, L = 10 m.
Compare your numerical results to the analytical solution:

Plot the analytical and numerical results in the same graph.

Answer:

Finite-difference methods (FDM) are discretizations used for solving differential


equations by approximating them with difference equations that finite differences
approximate the derivatives. FDMs convert a linear ordinary differential equations (ODE)
or non-linear partial differential equations (PDE) into a system of equations that can be
solved by matrix algebra techniques.
Step:
a) Divide solution domain into a series of discrete nodes separated by dx
b) Write the ODE for each node using finite difference formulas for the derivatives
c) Apply Boundary conditions and write system of algebraic equations in matrix form.

Discretize the domain:

0 2 4 6 8 10
There are 4 unknown y values

The second order Finite Difference approximation for a second derivative:


𝑑2 𝑦 𝑦𝑖+1 −2𝑦𝑖 +𝑦𝑖−1
= + 𝑂(ℎ2 )………………………………………………………….(4.1)
𝑑𝑡 2 ℎ2
Then, from the given equation, we can rearrange that into a finite difference equation:
𝑦𝑖+1 − 2𝑦𝑖 + 𝑦𝑖−1 𝑤𝐿𝑥𝑖 𝑤𝑥𝑖2
𝐸𝐼 ( )= −
𝑑𝑥 2 2 2

26
Alfarizki Qodri - 13617030

Multiply that with dx2


𝑤(𝑑𝑥 2 )
𝑦𝑖+1 − 2𝑦𝑖 + 𝑦𝑖−1 = (𝐿𝑥𝑖 − 𝑥𝑖2 )………………………………………………(4.2)
2𝐸𝐼
From eq (4.2), we can define y,
On node 1,
𝑦𝑖−1 = 𝑦0 (𝐵𝐶)
On node 4,
𝑦𝑖+1 = 𝑦5 (𝐵𝐶)
If we arrange that into some matrices, it will be:

 2 1 0 0  y2   Lx 2  x 22  y1 
 
 1 2 1
 0   y 3  wdx 2  Lx 3  x3 2 

0 1  2 1   y 4  2 EI  Lx 4  x 42 
    
0 0 1  2  y 5   Lx 5  x5  y 6 
2

A y B

clear all
clc

%known variable
w=1000;
L=10;
E=70*10^9;
I=800;

%matrix initiation
x0=0;
xL=10;
dx=2;
n=(xL-x0)/dx;
x(1)=0;
y(1)=0; y(5)=0;
x=zeros([1,n+1]);
A=zeros([n-1,n-1]);
B=zeros([n+1,1]);
for i=1:n
x(i+1)=x(i)+dx;
end

for i=1:n+1
if i~=1 && i~=n && i~=n+1
A(i,i)=-2;
A(i+1,i)=1;
A(i,i+1)=1;
else if i==n
A(i,i)=-2;
else if i==n+1
A(i,i)=1;
end
end
end
B(i,1)=(w*L*x(i)*dx^2/(2*E*I))-(w*x(i)^2*dx^2/(2*E*I));
end

27
Alfarizki Qodri - 13617030

A(1,1)=1;
%solve tridiagonal matrix
for i=1:n+1
if(i~=n+1)
aa(i)=A(i+1,i);
cc(i)=A(i,i+1);
end
bb(i)=A(i,i);
end
[a,b,c]=LUDecompo(aa,bb,cc);
y=DecOriginalA(a,b,c,B);
u1=plot(x,y);
hold on

%Analytical
xx=0:2:10;
f=(w*L*(xx).^3/(12*E*I))-(w*(xx).^4/(24*E*I))-(w*L^3*xx/(24*E*I));
u2=plot(xx,f);
legend([u1,u2],'Finite Difference Method','Analytical');
xlabel('L');
ylabel('y');

LuDecompo.m function program


%LU Decomposition
function [c,d,e] = LUdec(c,d,e)
n = length(d);
for k = 2:n
lambda = c(k-1)/d(k-1);
d(k) = d(k) - lambda*e(k-1);
c(k-1) = lambda;
end
end

DecOriginalA.m function program


%Decomposition of original A
function x = LUsolA(c,d,e,b)
n = length(d);
for k = 2:n % Forward substitution
b(k) = b(k) - c(k-1)*b(k-1);
end
b(n) = b(n)/d(n); % Back substitution
for k = n-1:-1:1
b(k) = (b(k) -e(k)*b(k+1))/d(k);
end
x = b;
end

Run those programs will create the comparison plot of the numerical and analytical
results with the known variable.

28
Alfarizki Qodri - 13617030

Figure 4.1 FD Method vs Analytical

5. Use Liebmann’s method (Gauss-Seidel) to solve for the temperature of the heated plate in
this figure. Employ overrelaxation with a value of 1.5 for the weighting factor and iterate
to 𝜀" = 1%

Answer:
Liebmann’s Method:
𝑇𝑖−1,𝑗 +𝑇𝑖,𝑗+1 +𝑇𝑖,𝑗−1
𝑇𝑖,𝑗 = ……………………………………………………………….(5.1)
4
And solved iteratively for j = 1 to n and i = 1 to m.

29
Alfarizki Qodri - 13617030

Overrelaxation is sometimes employed to accelerate the rate of convergence by applying


the following formula after each iteration:
𝑛𝑒𝑤 𝑜𝑙𝑑 𝑜𝑙𝑑
𝑇𝑖,𝑗 = 𝜆𝑇𝑖,𝑗 + (1 − 𝜆)𝑇𝑖,𝑗 ………………………………………………………...(5.2)
𝜆 = weighting factor that is set between 1 and 2

As with the conventional Gauss-Seidel method, the iterations are repeated until the
absolute values of all the percent relative errors (𝜀𝑎 ) fall below a prespecified stopping
criterion (𝜀𝑠 ). These percent relative errors are estimated by
𝑛𝑒𝑤 𝑜𝑙𝑑
𝑇𝑖,𝑗 − 𝑇𝑖,𝑗
|(𝜀𝑎 ) | = | 𝑛𝑒𝑤 | 100%
𝑇𝑖,𝑗
By doing iteration manually,
Using Eq (5.1) at i = 1, j = 1 is
0 + 60 + 0 + 0
𝑇11 = = 15
4
and applying overrelaxation yields
𝑇11 = 1.5(15) + (1 − 1.5)0 = 22.5

For i = 2, j = 1,
0 + 22.5 + 0 + 0
𝑇21 = = 5.625
4

𝑇21 = 1.5(5.625) + (1 − 1.5)0 = 8.4375


For i = 3, j = 1,
100 + 8.4375 + 0 + 0
𝑇31 = = 27.109375
4

𝑇31 = 1.5(27.109375) + (1 − 1.5)0 = 40.66406

The computation is repeated for the other rows. And the computation is continued until the
maximum error is less than the desired error.

30
Alfarizki Qodri - 13617030

clear all
clc

T = zeros(5,5);
T_left = 60;
T_right = 100;
T_top = 120;
T_bot = 0;
n = 5;
m = 5;
l = 1.5; %overrelaxation value
tol = 0.01; %tolerance or desired error
T = zeros(m,n);
T1 = zeros(m,n);
er = zeros(m,n);
for i=1:m
T(i,1) = T_left;
T(i,n) = T_right;
end
for j = 1:n
T(1,j) = T_top;

31
Alfarizki Qodri - 13617030

T(m,j) = T_bot;
end
for i = 2: m-1
for j= 2: n-1
T(i,j) = 0;
end
end
for iter= 1:100
for i= 2:m-1
for j=2:n-1
T1(i,j) = (T((i+1),j)+T((i-1),j)+T(i,(j-1))+T(i,(j+1)))./4;
T1(i,j) = l.*T1(i,j)+(1-l)*T(i,j);
er(i,j) = abs((T1(i,j)-T(i,j))/T1(i,j));
T(i,j) = T1(i,j);
end
end

if er<tol
break;
end
end

disp(['The Temperature distribution'])


disp(T)
disp(['Error'])
disp(er)
iter

The result of the program is:


The Temperature distribution
120.0000 120.0000 120.0000 120.0000 120.0000
60.0000 84.3825 93.1909 98.5904 100.0000
60.0000 63.9198 69.8422 81.0638 100.0000
60.0000 41.3886 41.6852 55.7932 100.0000
0 0 0 0 0

With 9 iterations and maximum error 0.57%

Put the result of temperature distribution into a figure,

84.38 93.19 98.59

63.92 69.84 81.06 Figure 5.1 The Temperature


Distribution

41.39 41.69 55.79

32
Alfarizki Qodri - 13617030

REFERENCES
Chapra, Steven. C and Raymond: Numerical Methods for Engineers
Kiusalaas, Jaan: Numerical Methods in Engineering with MATLAB

33

Você também pode gostar