NUMERIK
KELOMPOK III
NURUL FHAIKA SARWAN HENDRICK
(H061181309) (H061181313)
WINDY SARI
(H061181317)
SCRIPT
PYTHON
METODE
ALGORITMA
DIFFERENSIAL NUMERIK
•
Pengambilan h diharapkan pada nilai yang kecil agar error-nya kecil,
karena metode ini mempunyai error sebesar:
ALGORITMA DIFFERENSIAL NUMERIK SELISIH MAJU
Error
•
pada metode ini dapat dirumuskan sebagai :
ALGORITMA DIFFERENSIAL NUMERIK SELISIH MUNDUR
Error
•
pada metode ini dapat dirumuskan sebagai :
ALGORITMA DIFFERENSIAL NUMERIK SELISIH TENGAHAN
•
• 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
… …
… x-2*h x-h x x+h x+2*h …
_ _ _ _ _ _ _ _ SCRIPT PYTHON _ _ _ _ _ _ _ _
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
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