Anda di halaman 1dari 24

Modul Kuliah

Pengantar Komputasi dan Metode Numerik

Dosen Pengampu
Anif Jamaluddin

Pendidikan Fisika
Fakultas Keguruan dan Ilmu Pendidikan
Universitas Sebelas Maret
2022
Kata Pengantar

Pada modul numerik kali ini akan dibahas beberapa metode numerik yang dikelompokan menjadi
beberapa sub bab/bagian yaitu : persamaan non-linear, sistem persamaan liner dan diferensiasi
nuerik. Untuk bab persamaan Non-Linear menggunakan Metode Biseksi dan Newton-Raphson,
Bab Sistem Persamaan Linear adalah metode eliminasi gaus dan matrik sistem persamaan
linear. Pada Bab Diferensiasi numerik akan membahas tentang metode euler dan beda hingga.
Pada setiap bab akan dijelaskan secara singkat tentang materi tersebut, serta prosedur
penyelesaian numerik. Selanjutnya akan ditampilkan contoh pemrograman dengan
menggunakan octave.
Semoga modul ini dapat bermanfaat sebagai bahan pendamping perkuliahan pengantar
komputasi dan numerik.

Surakarta, 5 Desember 2022

Anif Jamaluddin
BAB I Metode Numerik

1.1 Pengantar Metode Numerik


Model matematika merupakan bagian integral dalam memecahkan masalah teknik.
Terdapat beberapa model matematika yang berasal dari prinsip-prinsip teknik dan sains, selain
itu model tersebut dapat diperoleh dari data eksperimen. Dalam penggunaanya, model
matematika memerlukan prosedur matematika yang diantaranya meliputi : Persamaan nonlinier,
persamaan linear simultan, pemasangan kurva dengan interpolasi atau regresi, integrasi, dan
persamaan diferensial.
Seringkali, model matematika tersebut rumit dan tidak dapat diselesaikan dengan metode analitik,
yaitu metode penyelesaian model matematika dengan rumus-rumus aljabar yang sudah lazim.
Analisis numerik adalah studi tentang algoritma yang menggunakan pendekatan numerik
(berlawanan dengan manipulasi simbolik) untuk masalah analisis matematis (yang dibedakan
dari matematika diskrit). Ini adalah studi tentang metode numerik yang berupaya menemukan
solusi perkiraan masalah daripada yang tepat.

1.2 Kesalahan
Dalam analisis numerik apa pun, kesalahan akan muncul selama perhitungan. Untuk dapat
menangani masalah kesalahan, kita perlu

• mengidentifikasi dari mana kesalahan itu berasal, diikuti oleh


• mengukur kesalahan, dan terakhir
• meminimalkan kesalahan sesuai kebutuhan kita.
Pada bab ini, kita akan berkonsentrasi bagaimana menghitung kesalahan.misal :
Turunan dari suatu fungsi f(x) pada nilai tertentu dapat dihitung dengan :

f ( x + h) − f ( x )
f ' ( x) 
h
Contoh :

Dengan Untuk 𝑓(𝑥) = 9𝑒 0.3𝑥 dan h = 0.3 tentukan nilai f’(x) secara analitik dan numerik untuk
x=3?
Jawab :
Solusi analitik untuk x=3

𝑓(𝑥) = 9𝑒 0.3𝑥

sehingga 𝑓′(𝑥) = 9(0.3)𝑒 0.3𝑥

𝑓′(3) = (2.7)𝑒 0.3(3)

𝑓′(3) = (2.7)(2.718)0.9
𝑓′(3) = 6.6409
Solusi numerik

f ( x + h) − f ( x )
f ' ( x) 
h
𝑓(3 + 0.3) − 𝑓(3)
𝑓′(3) ≈
0.3
𝑓(3.3) − 𝑓(3)
𝑓′(3) ≈
0.3
9𝑒 0.3(3.3) − 9𝑒 0.3(3)
𝑓′(3) ≈
0.3
9𝑒 0.3(3.3) − 9𝑒 0.3(3)
𝑓′(3) ≈
0.3

′ (3)
9𝑒 (0.99) − 9𝑒 (0.9)
𝑓 ≈
0.3
9(2.6910) − 9(2.4596)
𝑓 ′ (3) ≈
0.3
24.2211 − 22.1364
𝑓 ′ (3) ≈
0.3
24.2211 − 22.1364
𝑓 ′ (3) ≈
0.3
F’(3)= 6.9487
Error = |hasil numerik - hasil analitik|
=|6.9487-6.6409|
=0.3078

1.3 Deret Taylor


Penggunaan deret Taylor ada dalam begitu banyak aspek metode numerik sehingga sangat
penting untuk bahas dan penerapannya. Misalnya :

x2 x4 x6
cos(x) = 1 − + − + (1)
2! 4! 6!

x3 x5 x7
sin( x) = x − + − + (2)
3! 5! 7!

x 2 x3
ex = 1+ x + + + (3)
2! 3!
Secara sederhana dapat dituliskan : f ( x )

f (x ) 2 f (x ) 3
f (x + h ) = f (x ) + f (x )h + h + h + (4)
2! 3!
f ( x ) dan continue pada x and x + h .

Contoh kasus

Tentukan nilia f (6 ) jika hasil yang diketahui untuk f (4) = 125 , f (4 ) = 74 , f (4) = 30 ,
f (4) = 6 dan turunan tertinggi dari f ( x ) pada saat x = 4 adalah 0.

Jawab:

h2 h3
f (x + h ) = f (x ) + f (x )h + f (x ) + f (x ) + 
2! 3!
x=4
h = 6−4
=2
Pada saat turunan tertinggi f ( x ) adalah 0 saat x = 4 .

22 23
f (4 + 2) = f (4) + f (4)2 + f (4) + f (4)
2! 3!

 2 2   23 
f (6) = 125 + 74(2) + 30  + 6 
 2!   3! 
= 125 + 148 + 60 + 8
= 341
BAB II Persamaan Non-Linear

2.1 Metode Biseksi (Bisection Method)


Definisi
Salah satu metode numerik untuk mencari solusi akar pada persamaan polinomial adalah metode
bisection (atau dalam bahasa indonesia metode bagi dua). Metode ini bisa mencari akar
polinomial real derajat berapa saja. Metode Bisection merupakan metode mencari akar suatu
fungsi dengan menetapkan batas interval di mana di dalam interval tersebut memuat nilai akar
yang dicari. Nanti interval ini dibagi dua kemudian diambil interval baru yang masih memuat nilai
akar. Proses pembagian ini dilakukan terus menerus sehingga batas interval mendekati nilai akar.
Langkah-langkah

Contoh :

Untuk range waktu dari 1,5 , tentukan iterasi kedua dari persamaan berikut ini dengan
menggunakan metode biseksi te −t − 0.3 = 0
Jawab :

f (t ) = te −t − 0.3
Dalam rentan waktu tersebut :

tu = 5
t = 1

Sehingga dapat dituliskan fungsinya adalah t  and t u

f (t u ) = 5e −5 − 0.3
= −0.2663
f (t  ) = 1e −1 − 0.3
= 0.0679

Sehingga,
f (t u ) f (t  ) = f (5) f (1)
= (−0.2663)(0.0679)
= −0.0181  0
Jadi setidaknya ada satu akar di antaranya t  and t u .

Iterasi 1

Estimasi
t + tu
tm =
2
1+ 5
=
2
=3
f (t m ) = 3e −3 − 0.3
= −0.1506

Sehingga,
f (t  ) f (t m ) = f (1) f (3)
= (0.0679)(−0.1506)
= −0.0102  0

Jadi tebakan atas dan bawah yang baru untuk akarnya adalah, Selanjutnya t  dan t m ,

t = t = 1
tu = t m = 3

Iterasi ke 2

Estimasi untuk

t + tu
tm =
2
1+ 3
=
2
=2

2.2 Metode Newton Raphson


Methods such as the bisection method and the false position method of finding roots of a
nonlinear equation f ( x) = 0 require bracketing of the root by two guesses. Such methods are
called bracketing methods. These methods are always convergent since they are based on
reducing the interval between the two guesses so as to zero in on the root of the equation.
In the Newton-Raphson method, the root is not bracketed. In fact, only one initial guess
of the root is needed to get the iterative process started to find the root of an equation. The
method hence falls in the category of open methods. Convergence in open methods is not
guaranteed but if the method does converge, it does so much faster than the bracketing
methods.

Langkah

The steps of the Newton-Raphson method to find the root of an equation f ( x ) = 0 are

1. Evaluate f ( x ) symbolically
2. Use an initial guess of the root, xi , to estimate the new value of the root, xi +1 , as
f (xi )
xi +1 = xi −
f (xi )

3. Find the absolute relative approximate error a as


xi +1 − xi
a =  100
xi +1

4. Compare the absolute relative approximate error with the pre-specified relative error tolerance,
s . If a > s , then go to Step 2, else stop the algorithm. Also, check if the number of
iterations has exceeded the maximum number of iterations allowed. If so, one needs to
terminate the algorithm and notify the user.

f (x)

f (xi) [xi, f (xi)]

f (xi+1)

θ
x
xi+2 xi+1 xi

Gambar Ilustrasi metode Newton-Raphson


Contoh :

Tentukan iterasi berikutnya untuk persamaan x − 4 = 0 menggunakan metode newton-raphson, jika


2

diketaui nilai inisial adalah 3.


Jawab :

f ( xi )
xi +1 = xi −
f ( xi )

Pilih i = 0,

x0 = 3
f ( x0 ) = x0 − 4
2

= 32 − 4
=5
f ( x0 ) = 2 x0
= 23
=6

Jadi,
f ( x0 )
x1 = x0 −
f ( x0 )
5
= 3−
6
= 2.166
BAB III Sistem Persamaan Linear

Salah satu metode yang sangat popular untuk menyelesaikan persamaan pada sistem liner dengan metode
numerik adalah menggunakan eliminasi gauss. Pendakatan yang dilakukan untuk menyelesaikan
persamaan adalah sebagai berikut ini dengan set n persamaan dan variabel n yang tidak diketahui.
a11x1 + a12 x2 + a13 x3 + ... + a1n xn = b1

a21x1 + a22 x2 + a23 x3 + ... + a2n xn = b2


. .

. .

. .

an1x1 + an 2 x2 + an3 x3 + ... + ann xn = bn


Gaussian elimination consists of two steps

Forward Elimination of Unknowns: In this step, the unknown is eliminated in each equation starting with
the first equation. This way, the equations are reduced to one equation and one unknown in each
equation.

Back Substitution: In this step, starting from the last equation, each of the unknowns is found.

Forward Elimination of Unknowns:

In the first step of forward elimination, the first unknown, x1 is eliminated from all rows below the first row.
The first equation is selected as the pivot equation to eliminate x1 . So, to eliminate x1 in the second
equation, one divides the first equation by a11 (hence called the pivot element) and then multiplies it by
a 21 . This is the same as multiplying the first equation by a 21 / a11 to give

a 21 a a
a 21 x1 + a12 x 2 + ... + 21 a1n x n = 21 b1
a11 a11 a11
Now, this equation can be subtracted from the second equation to give

 a   a  a
 a 22 − 21 a12  x2 + ... +  a 2 n − 21 a1n  xn = b2 − 21 b1
 a11   a11  a11

or

 x2 + ... + a2 n xn = b2


a22

where
a21
 = a22 −
a22 a12
a11

a21
a2 n = a2 n − a1n
a11

This procedure of eliminating x1 , is now repeated for the third equation to the n th equation to reduce the
set of equations as

a11 x1 + a12 x2 + a13 x3 + ... + a1n xn = b1

 x2 + a23
a22  x3 + ... + a2 n xn = b2

 x2 + a33
a32  x3 + ... + a3 n xn = b3

. . .

. . .

. . .

an 2 x2 + an 3 x3 + ... + ann


 xn = bn

This is the end of the first step of forward elimination. Now for the second step of forward elimination, we
start with the second equation as the pivot equation and a22  as the pivot element. So, to eliminate x 2 in
 .
 (the pivot element) and then multiply it by a32
the third equation, one divides the second equation by a22
This is the same as multiplying the second equation by  / a22
a32  and subtracting it from the third equation.
This makes the coefficient of x 2 zero in the third equation. The same procedure is now repeated for the
fourth equation till the n th equation to give
a11 x1 + a12 x2 + a13 x3 + ... + a1n xn = b1

 x2 + a23
a22  x3 + ... + a2 n xn = b2

 x3 + ... + a3n xn = b3


a33

. .

. .

. .

an3 x3 + ... + ann


 xn = bn

The next steps of forward elimination are conducted by using the third equation as a pivot equation and
so on. That is, there will be a total of n − 1 steps of forward elimination. At the end of n − 1 steps of
forward elimination, we get a set of equations that look like

a11 x1 + a12 x 2 + a13 x3 + ... + a1n xn = b1


 x2 + a23
a22  x3 + ... + a2 n xn = b2

 x3 + ... + a3n xn = b3


a33
. .

. .

. .
(n −1)
a nn xn = bn(n −1)

Back Substitution:

Now the equations are solved starting from the last equation as it has only one unknown.

bn( n −1)
xn = ( n −1)
a nn

Then the second last equation, that is the (n − 1) th equation, has two unknowns: x n and xn−1 , but x n is
already known. This reduces the (n − 1) th equation also to one unknown. Back substitution hence can
be represented for all equations by the formula

bi(i −1) −  aij(i −1) x j


n

j =i +1
xi = for i = n − 1, n − 2, ,1
aii(i −1)

and

bn( n −1)
x n = ( n −1)
a nn
BAB IV Differensiasi Numerik

4.1 Metode Euler


Metode Euler merupakan salah satu dari banyak metode untuk menyelesaikan secara numerik
untuk persamaan diferensial. Metode ini dipilih pilih karena relative sederhana dalam
menyelesaikan secara numerik.
Metode Euler didasarkan pada pendekatan grafik solusi y(x) dengan urutan perkiraan garis
singgung dihitung secara berurutan, dalam "langkah". Maka, tugas pertama kita adalah
menurunkan rumus yang berguna untuk perkiraan garis singgung di setiap langkah.
Secara umum metode Euler merupakan solusi numerik persamaan deferensial order 1 dengan
mengikuti deret taylor
Asumsi yang diterapkan pada Metode Euler adalah suku terakhir adalah turunan ke dua yang
dapat diabaikan sehingga :

Nilai turunan dari y dengan metode Eular didapatkan dari mengekstrapolasi garis linier diinterval
h, sehingga semakin banyak interval nilai h maka semakin besar error yang didapatkan.

Langkah-Langkah

Contoh Program :
clear all
clc
format long

b=4; batas atas


a=0; batas bawah
h=0.5;
N=(b-a)/h;
y0=1; nilai y awal
x0=0; nilai x awal

%perubahan t per step

for i=1:N x(i)=a+(i*h);


end

%solusi y
y(1)=y0+h*(-2*x0^3+12*x0^2-20*x0+8.5);
for i=2:N
k=i-1
y(i)=y(k)+h*(-2*x(k)^3+12*x(k)^2-20*x(k)+8.5);
end

%solusi analitik
for i=1:N
w(i)=-0.5*x(i)^4+4*x(i)^3-10*x(i)^2+8.5*x(i)+1;
end
Plot (x,y,x,w);

4.2 Metode Beda Hingga

The finite difference method is used to solve ordinary differential equations that have conditions
imposed on the boundary rather than at the initial point. These problems are called boundary-
value problems. In this chapter, we solve second-order ordinary differential equations of the
form
d2y
= f ( x, y, y ' ), a  x  b , (1)
dx 2
with boundary conditions

y (a ) = ya and y(b) = yb (2)

Many academics refer to boundary value problems as position-dependent and initial value
problems as time-dependent. That is not necessarily the case as illustrated by the following
examples.
The differential equation that governs the deflection y of a simply supported beam under
uniformly distributed load (Figure 1) is given by

d 2 y qx( L − x )
= (3)
dx 2 2 EI
where
x = location along the beam (in)
E = Young’s modulus of elasticity of the beam (psi)
I = second moment of area (in4)
q = uniform loading intensity (lb/in)

L = length of beam (in)


The conditions imposed to solve the differential equation are

y ( x = 0) = 0 (4)

y ( x = L) = 0

Clearly, these are boundary values and hence the problem is considered a boundary-value
problem.
Figure 1 Simply supported beam with uniform distributed load.

Now consider the case of a cantilevered beam with a uniformly distributed load (Figure 2). The
differential equation that governs the deflection y of the beam is given by

d 2 y q( L − x ) 2
= (5)
dx 2 2 EI
where
x = location along the beam (in)
E = Young’s modulus of elasticity of the beam (psi)
I = second moment of area (in4)
q = uniform loading intensity (lb/in)

L = length of beam (in)


The conditions imposed to solve the differential equation are

y ( x = 0) = 0 (6)

dy
( x = 0) = 0
dx
Clearly, these are initial values and hence the problem needs to be considered as an initial
value problem.
Figure 2 Cantilevered beam with a uniformly distributed load.
Example 1
The deflection y in a simply supported beam with a uniform load q and a tensile axial load T is
given by

d 2 y Ty qx( L − x)
− = (E1.1)
dx 2 EI 2 EI
where
x = location along the beam (in)
T = tension applied (lbs)
E = Young’s modulus of elasticity of the beam (psi)
I = second moment of area (in4)
q = uniform loading intensity (lb/in)

L = length of beam (in)


Figure 3 Simply supported beam for Example 1.

Given,

T = 7200 lbs, q = 5400 lbs/in, L = 75 in , E = 30 Msi , and I = 120 in 4 ,

a) Find the deflection of the beam at x = 50" . Use a step size of x = 25" and approximate the
derivatives by central divided difference approximation.

b) Find the relative true error in the calculation of y (50) .

Solution
a) Substituting the given values,

d2y 7200 y (5400) x(75 − x )


− =
dx 2
(30  10 )(120) 2(30  106 )(120)
6

d2y
2
− 2  10−6 y = 7.5  10−7 x(75 − x) (E1.2)
dx

d2y
Approximating the derivative at node i by the central divided difference approximation,
dx 2

Figure 4 Illustration of finite difference nodes using


central divided difference method.
d 2 y yi +1 − 2 yi + yi −1
 (E1.3)
dx 2 ( x ) 2
We can rewrite the equation as

yi +1 − 2 yi + yi −1
− 2  10 −6 yi = 7.5  10 −7 xi (75 − xi ) (E1.4)
(x) 2

Since x = 25 , we have 4 nodes as given in Figure 3

Figure 5 Finite difference method from x = 0 to x = 75 with x = 25 .

The location of the 4 nodes then is

x0 = 0

x1 = x0 + x = 0 + 25 = 25

x 2 = x1 + x = 25 + 25 = 50

x3 = x2 + x = 50 + 25 = 75

Writing the equation at each node, we get

Node 1: From the simply supported boundary condition at x = 0 , we obtain

y1 = 0 (E1.5)

Node 2: Rewriting equation (E1.4) for node 2 gives

y 3 − 2 y 2 + y1
2
− 2  10 −6 y 2 = 7.5  10 −7 x 2 (75 − x 2 )
(25)

0.0016y1 − 0.003202y 2 + 0.0016y3 = 7.5  10−7 (25)(75 − 25)

0.0016y1 − 0.003202y 2 + 0.0016y3 = 9.375 10−4 (E1.6)

Node 3: Rewriting equation (E1.4) for node 3 gives

y 4 − 2 y3 + y 2
2
− 2  10 −6 y3 = 7.5  10 −7 x3 (75 − x3 )
(25)
0.0016y 2 − 0.003202y3 + 0.0016y 4 = 7.5  10−7 (50)(75 − 50)

0.0016y 2 − 0.003202y3 + 0.0016y 4 = 9.375 10−4 (E1.7)

Node 4: From the simply supported boundary condition at x = 75 , we obtain

y4 = 0 (E1.8)

Equations (E1.5-E1.8) are 4 simultaneous equations with 4 unknowns and can be written in
matrix form as

 1 0 0 0   y1  0 
0.0016 − 0.003202 0.0016 0

  y  9.375  10 − 4 
  2  =  
 0 0.0016  
− 0.003202 0.0016 y 3   9.375  10 −4 

    
 0 0 0 1   y 4  0 

The above equations have a coefficient matrix that is tridiagonal (we can use Thomas’ algorithm
to solve the equations) and is also strictly diagonally dominant (convergence is guaranteed if we
use iterative methods such as the Gauss-Siedel method). Solving the equations we get,

 y1  0 
y   
 2  = − 0.5852
 y 3  − 0.5852
   
 y 4  0 

y (50) = y ( x 2 )  y 2 = −0.5852"

The exact solution of the ordinary differential equation is derived as follows. The homogeneous
part of the solution is given by solving the characteristic equation

m 2 − 2  10 −6 = 0
m = 0.0014142
Therefore,

y h = K1e 0.0014142 x + K 2 e −0.0014142 x

The particular part of the solution is given by

y p = Ax 2 + Bx + C

Substituting the differential equation (E1.2) gives


d 2 yp
2
− 2  10 −6 y p = 7.5  10 −7 x(75 − x)
dx

d2
2
( Ax 2 + Bx + C ) − 2  10−6 ( Ax 2 + Bx + C ) = 7.5  10−7 x(75 − x)
dx

2 A − 2  10−6 ( Ax 2 + Bx + C ) = 7.5  10−7 x(75 − x)

− 2  10−6 Ax 2 − 2  10−6 Bx + (2 A − 2  10−6 C ) = 5.625 10−5 x − 7.5  10−7 x 2


Equating terms gives

− 2  10 −6 A = −7.5  10 −7

− 2  10 −6 B = −5.625  10 −5

2 A − 2  10 −6 C = 0
Solving the above equation gives

A = 0.375
B = −28.125

C = 3.75  10 5
The particular solution then is

y p = 0.375 x 2 − 28.125 x + 3.75  10 5

The complete solution is then given by

y = 0.375x 2 − 28.125x + 3.75  105 + K1e 0.0014142x + K 2 e −0.0014142x


Applying the following boundary conditions

y ( x = 0) = 0

y ( x = 75) = 0

we obtain the following system of equations

K1 + K 2 = −3.75  105

1.1119K1 + 0.89937K 2 = −3.75  105


These equations are represented in matrix form by

 1 1   K1  − 3.75  105 
1.1119 0.89937  K  =  5
   2  − 3.75  10 
A number of different numerical methods may be utilized to solve this system of equations such
as the Gaussian elimination. Using any of these methods yields

 K1  − 1.775656226 105 
K  =  5
 2  − 1.974343774 10 
Substituting these values back into the equation gives

y = 0.375x 2 − 28.125x + 3.75  105 − 1.775656266 105 e 0.0014142x − 1.974343774 105 e −0.0014142x
Unlike other examples in this chapter and in the book, the above expression for the deflection of
the beam is displayed with a larger number of significant digits. This is done to minimize the
round-off error because the above expression involves subtraction of large numbers that are
close to each other.

b) To calculate the relative true error, we must first calculate the value of the exact solution at
y = 50 .

y(50) = 0.375(50) 2 − 28.125(50) + 3.75  105 − 1.775656266 105 e 0.0014142(50)

− 1.974343774  10 5 e −0.0014142 (50 )


y (50) = −0.5320

The true error is given by

E t = Exact Value – Approximate Value

Et = −0.5320 − (−0.5852)

Et = 0.05320

The relative true error is given by

True Error
t =  100%
True Value
0.05320
t =  100%
− 0.5320
t = −10%
Daftar Pustaka

• Svein Linge, Hans Petter Langtangen, 2016, Programming for Computations –


MATLAB/Octave, Springer Heidelberg Dordrecht London
• Anif Jamaluddin, 2002, Kajian pola dan distribusi sebaran cemaran udara (NO2)
menggunakan model-K dengan metode beda hingga, Skripsi, Universitas Diponegoro,
Semarang, Indonesia
• Alfio Quarteroni, Fausto Saleri, Paola Gervasio, 2010, Scientific Computing with MATLAB
and Octave, Springer Heidelberg Dordrecht London New York
• James F. Epperson, 2013, An Introduction to Numerical Method and Analysis, Wiley &
Sons, Canada

Anda mungkin juga menyukai