Escolar Documentos
Profissional Documentos
Cultura Documentos
Oleh:
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)
Answer:
Rearrange the function f(x) = 0 so that x is on the left-hand side of the equation:
x = g (x) ……………………………………………………………………………….(1.1)
𝑣𝑐
𝑚= −(
𝑐
)𝑡
. …………………………………………………………………..(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
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
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:
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.
%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: ');
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
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
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
C=
15
Alfarizki Qodri - 13617030
X=
>>
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
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
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
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';
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.
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';
21
Alfarizki Qodri - 13617030
22
Alfarizki Qodri - 13617030
23
Alfarizki Qodri - 13617030
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';
24
Alfarizki Qodri - 13617030
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:
Answer:
0 2 4 6 8 10
There are 4 unknown y values
26
Alfarizki Qodri - 13617030
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');
Run those programs will create the comparison plot of the numerical and analytical
results with the known variable.
28
Alfarizki Qodri - 13617030
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
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
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
32
Alfarizki Qodri - 13617030
REFERENCES
Chapra, Steven. C and Raymond: Numerical Methods for Engineers
Kiusalaas, Jaan: Numerical Methods in Engineering with MATLAB
33