Anda di halaman 1dari 25

METODE

NUMERIK
KELOMPOK III
NURUL FHAIKA SARWAN HENDRICK
(H061181309) (H061181313)

WINDY SARI
(H061181317)

This Photo by Unknown Author is licensed under CC BY


DIFFERENSIAL NUMERIK

SCRIPT
PYTHON
METODE

ALGORITMA
DIFFERENSIAL NUMERIK

Metode Selisih Maju Metode Selisih Mundur

Metode Selisih Tengahan


DIFFERENSIAL NUMERIK

Perhitungan perubahan tinggi (selisih tinggi) dan perubahan jarak kalkulus


banyak digunakan untuk keperluan perhitungan geometrik, yang berhubungan
dengan perubahan nilai per satuan waktu atau jarak.
Secara kalkulus, didefinisikan sebagai perbandingan
•  

penentuan titik puncak kurva y = f(x) dy/dx = 0


1 Metode Selisih Maju

Metode selisih maju merupakan metode yang mengadopsi secara


langsung definisi differensial dan dituliskan :

•  
Pengambilan h diharapkan pada nilai yang kecil agar error-nya kecil,
karena metode ini mempunyai error sebesar:
ALGORITMA DIFFERENSIAL NUMERIK SELISIH MAJU

Definisikan fungsi f(x) yang akan dicari nilai turunannya


Definisikan fungsi turunan f’ eksak (x) sebenarnya
• Masukkan nilai pendekatan awal : nilai x dan nilai step h
Hitung
Tampilkan nilai x, f(x), f’(x) dan f’’(x)
2 Metode Selisih Mundur

Metode selisih mundur merupakan kebalikan dari metode selisih


maju. dapat dituliskan :

Error
•  
pada metode ini dapat dirumuskan sebagai :
ALGORITMA DIFFERENSIAL NUMERIK SELISIH MUNDUR

Definisikan fungsi f(x) yang akan dicari nilai turunannya


Definisikan fungsi turunan f’ eksak (x) sebenarnya
• Masukkan nilai pendekatan awal : nilai x dan nilai step h
Hitung
Tampilkan nilai x, f(x), f’(x) dan f’’(x)
3 Metode Selisih Tengahan

Metode selisih tengahan merupakan metode pengambilan perubahan


dari dua titik sekitar dari titik yang diukur maju, dapat dituliskan :

Error
•  
pada metode ini dapat dirumuskan sebagai :
ALGORITMA DIFFERENSIAL NUMERIK SELISIH TENGAHAN

Definisikan fungsi f(x) yang akan dicari nilai turunannya


Definisikan fungsi turunan f’ eksak (x) sebenarnya
Masukkan nilai pendekatan awal : nilai x dan nilai step h
•  
Hitung
Tampilkan nilai x, f(x), f’(x) dan f’’(x)
• Differensial tingkat tinggi merupakan
proses pendifferensialan secara terus-
menerus, hingga tingkatan yang
ditentukan.
PENYELESAIAN • Jadi, Differensial tingkat tinggi bukan
DIFFERENSIAL hanya turunan pertama namun termasuk
TINGKAT juga turunan kedua, ketiga dan
seterusnya.
TINGGI • Differensial tingkat tinggi juga dapat
dilakukan oleh 3 metode yaitu selisih
maju, tengah dan mundur
• Differensial Tingkat Dua untuk metode selisih maju

•  
• Differensial Tingkat Dua untuk metode selisih mundur

•  
• Differensial Tingkat Dua untuk metode selisih tengah

•  
• Differensial Tingkat Tiga untuk metode selisih tengah

•  
CONTOH SOAL
_ _ _ _ _ _ _ _ CONTOH I _ _ _ _ _ _ _ _

 
Carilah turunan pertama dan turunan kedua pada x = 0.1

Bandingkan solusi numerik pada saat h = 0.1 , 0.01 , dan 0.001


Hasil analisis differensiasi :

… …
… x-2*h x-h x x+h x+2*h …
_ _ _ _ _ _ _ _ SCRIPT PYTHON _ _ _ _ _ _ _ _

f = lambda x: 0.1*x**5 - 0.2*x**3 + 0.1*x - 0.2


HASIL
x = 0.1
h = 0.1
runfile('F:/EXAMPLE 1.py', wdir='F:')
f'(x) err f''(x) err

H = 0.1
df1 = 0.09405 FFD 0.086310 -0.007740 -0.222000 -0.104000
df2 = -0.118 BFD 0.098010 0.003960 -0.117000 0.001000
CFD 0.092160 -0.001890 -0.000011 0.117989
print("\t f'(x)\t\t err\t\t f''(x)\t\t err")
#Forward differences runfile('F:/EXAMPLE 1.py', wdir='F:')
dff1 = (f(x+h)-f(x))/h f'(x) err f''(x) err

H = 0.01
dff2 = (f(x+2*h)-2*f(x+h)+f(x))/h**2 FFD 0.093441 -0.000609 -0.129327 -0.011327
print("FFD\t% f\t% f\t% f\t% f" % (dff1, dff1-df1, dff2, dff2-df2)) BFD 0.094621 0.000571 -0.117990 0.000010
CFD 0.094031 -0.000019 -0.000000 0.118000
#Backward differences
dff1 = (f(x)-f(x-h))/h runfile('F:/EXAMPLE 1.py', wdir='F:')
dff2 = (f(x+h)-2*f(x)+f(x-h))/h**2
f'(x) err f''(x) err

H = 0.001
print("BFD\t% f\t% f\t% f\t% f" % (dff1, dff1-df1, dff2, dff2-df2))
FFD 0.093991 -0.000059 -0.119139 -0.001139
BFD 0.094109 0.000059 -0.118000 0.000000
#Central differences
CFD 0.094050 -0.000000 -0.000000 0.118000
dff1 = (f(x+h)-f(x-h))/(2*h)
dff2 = (f(x+2*h)-2*f(x)+f(x-2*h))/4*h**2
print("CFD\t% f\t% f\t% f\t% f" % (dff1, dff1-df1, dff2, dff2-df2))
_ _ _ _ _ _ _ _ CONTOH II _ _ _ _ _ _ _ _

 
Carilah turunan pertama dan turunan kedua fungsi
berikut berdasarkan domain [-1,1] dengan
menggunakan selisih tengahan kemudian plot
grafik dari fungsi dan turunannya. Nilai h = 0.01
_ _ _ _ _ _ _ _ SCRIPT PYTHON _ _ _ _ _ _ _ _
HASIL
runfile('F:/EXAMPLE 2.py', wdir='F:')
f'(x) = [ 0.00801 -0.021579 -0.04393458 -0.05982275 -0.06997625
import numpy as np -0.07509448
import matplotlib.pyplot as plt -0.07584357 -0.07285631 -0.0667322 -0.05803745 -0.04730494 -0.03503425
-0.02169166 -0.00771015 0.00651062 0.02060429 0.03423781 0.04711141
f = lambda x: 0.1*x**5 - 0.2*x**3 + 0.1*x 0.05895866 0.06954642 0.07867485 0.08617743 0.09192093 0.09580545
h = 0.1 0.09776436 0.09776436 0.09580545 0.09192093 0.08617743 0.07867485

x = np.linspace(-1,1) 0.06954642 0.05895866 0.04711141 0.03423781 0.02060429 0.00651062


-0.00771015 -0.02169166 -0.03503425 -0.04730494 -0.05803745 -0.0667322
-0.07285631 -0.07584357 -0.07509448 -0.06997625 -0.05982275 -0.04393458
#Central Differences
-0.021579 0.00801 ]
dff1 = (f(x+h)-f(x-h))/(2*h)
f''(x) = [-8.40000000e-05 -6.52308817e-05 -4.83793317e-05 -3.33637515e-
dff2 = (f(x+2*h)-2*f(x)+f(x-2*h))/4*h**2
05
print("f'(x) = ", dff1)
-2.01025423e-05 -8.51410552e-06 1.48315753e-06 9.97084548e-06
print("f''(x) = ", dff2)
1.70305570e-05 2.27438907e-05 2.71924453e-05 3.04578194e-05
3.26216117e-05 3.37654209e-05 3.39708455e-05 3.33194842e-05
#Plot 3.18929358e-05 2.97727987e-05 2.70406718e-05 2.37781537e-05
plt.plot(x,f(x),'-k',x,dff1,'--b',x,dff2,'-,r') 2.00668429e-05 1.59883382e-05 1.16242382e-05 7.05614157e-06
plt.xlabel('x') 2.36564697e-06 -2.36564697e-06 -7.05614157e-06 -1.16242382e-05
plt.ylabel('y') -1.59883382e-05 -2.00668429e-05 -2.37781537e-05 -2.70406718e-05
plt.legend(["f(x)","f'(x)","f''(x)"]) -2.97727987e-05 -3.18929358e-05 -3.33194842e-05 -3.39708455e-05
plt.grid() -3.37654209e-05 -3.26216117e-05 -3.04578194e-05 -2.71924453e-05
plt.show() -2.27438907e-05 -1.70305570e-05 -9.97084548e-06 -1.48315753e-06
8.51410552e-06 2.01025423e-05 3.33637515e-05 4.83793317e-05
6.52308817e-05 8.40000000e-05]
_ _ _ _ _ _ _ _ SCRIPT PYTHON _ _ _ _ _ _ _ _
HASIL
runfile('F:/EXAMPLE 2.py', wdir='F:')
import numpy as np f'(x) = [ 0.00801 -0.021579 -0.04393458 -0.05982275 -0.06997625
import matplotlib.pyplot as plt -0.07509448
-0.07584357 -0.07285631 -0.0667322 -0.05803745 -0.04730494 -0.03503425
f = lambda x: 0.1*x**5 - 0.2*x**3 + 0.1*x -0.02169166 -0.00771015 0.00651062 0.02060429 0.03423781 0.04711141

h = 0.1 0.05895866 0.06954642 0.07867485 0.08617743 0.09192093 0.09580545


0.09776436 0.09776436 0.09580545 0.09192093 0.08617743 0.07867485
x = np.linspace(-1,1)
0.06954642 0.05895866 0.04711141 0.03423781 0.02060429 0.00651062
-0.00771015 -0.02169166 -0.03503425 -0.04730494 -0.05803745 -0.0667322
#Central Differences
-0.07285631 -0.07584357 -0.07509448 -0.06997625 -0.05982275 -0.04393458
dff1 = (f(x+h)-f(x-h))/(2*h)
-0.021579 0.00801 ]
dff2 = (f(x+2*h)-2*f(x)+f(x-2*h))/4*h**2
f''(x) = [-8.40000000e-05 -6.52308817e-05 -4.83793317e-05 -3.33637515e-
print("f'(x) = ", dff1)
05
print("f''(x) = ", dff2)
-2.01025423e-05 -8.51410552e-06 1.48315753e-06 9.97084548e-06
1.70305570e-05 2.27438907e-05 2.71924453e-05 3.04578194e-05
#Plot 3.26216117e-05 3.37654209e-05 3.39708455e-05 3.33194842e-05
plt.plot(x,f(x),'-k',x,dff1,'--b',x,dff2,'-,r') 3.18929358e-05 2.97727987e-05 2.70406718e-05 2.37781537e-05
plt.xlabel('x') 2.00668429e-05 1.59883382e-05 1.16242382e-05 7.05614157e-06
plt.ylabel('y') 2.36564697e-06 -2.36564697e-06 -7.05614157e-06 -1.16242382e-05
plt.legend(["f(x)","f'(x)","f''(x)"]) -1.59883382e-05 -2.00668429e-05 -2.37781537e-05 -2.70406718e-05
plt.grid() -2.97727987e-05 -3.18929358e-05 -3.33194842e-05 -3.39708455e-05
plt.show() -3.37654209e-05 -3.26216117e-05 -3.04578194e-05 -2.71924453e-05
-2.27438907e-05 -1.70305570e-05 -9.97084548e-06 -1.48315753e-06
8.51410552e-06 2.01025423e-05 3.33637515e-05 4.83793317e-05
6.52308817e-05 8.40000000e-05]
_ _ _ _ _ _ _ _ CONTOH III _ _ _ _ _ _ _ _

 
Plot turunan pertama dari fungsi dengan domain [-
1,1] dengan menggunakan differensial selisih
maju, selisih mundur, dan selisih tengahan.
Bandingkan hasil plot dengan hasil teoritis pada h
= 0.1 , 0.01, dan 0.001

Secara teoritis
_ _ _ _ _ _ _ _ SCRIPT PYTHON _ _ _ _ _ _ _ _
import numpy as np
import matplotlib.pyplot as plt HASIL
f = lambda x: 0.1*x**5 - 0.2*x**3 + 0.1*x - 0.2
df = lambda x: 0.5*x**4 - 0.6*x**2 + 0.1

h = 0.1
x = np.linspace(-1,1)
plt.plot(x,df(x),'-k')

#Forward Difference
dff1 = (f(x+h) - f(x))/h
plt.plot(x,dff1,'-b')

#Backward Difference
H = 0.1 H = 0.01
dff1 = (f(x)-f(x-h))/h
plt.plot(x,dff1,'-r')

#Central Difference
dff1 = (f(x+h)-f(x-h))/(2*h)
plt.plot(x,dff1,'-g')

#Plot
plt.xlabel('x')
plt.ylabel('y')
plt.legend(["Theo.","FFD","BFD","CFD"])
plt.grid()
plt.show() H = 0.001
THANK YOU 
NEVER STOP LEARNING

Anda mungkin juga menyukai