Kalkulus 2.Comparison

mail@pastecode.io avatar
unknown
python
2 years ago
1.2 kB
3
Indexable
Never
# PERBANDINGAN AKHIR BEBERAPA METODE
import matplotlib.pyplot as plt

xlist_euler1 = euler(2, 0.1)[0]
ylist_euler1 = euler(2, 0.1)[1]
ylist_euler1nw = []
for c in range(len(ylist_euler1)):
  if c % 5 == 0:
    ylist_euler1nw.append(ylist_euler1[c])

yscipy = []
for a in y:
  for b in a:
    yscipy.append(b)

print(84*"-") ; print(26*" ", "PERBANDINGAN BEBERAPA METODE", 26*" ") ; print(84*"-")
dict5 = {}
for l in range(len(xlist_euler5)):
  dict5[l+1] = [xlist_euler5[l], ylistanl[l], ylist_euler5[l], ylist_euler1[l],ylist_RK2[l], ylist_RK4[l], yscipy[l]]
print ("{:<4} {:<6} {:<12} {:<14} {:<14} {:<10} {:<10} {:<10}".format('No','x','y analitik','y Euler 0.5','y Euler 0.1','y RK 2','y RK 4', 'y scipy'))
for n, v in dict5.items():
    x, yanal, yeuler5, yeuler1, yrk2, yrk4, yscp = v
    print ("{:<4} {:<6.1f} {:<12.5f} {:<14.5f} {:<14.5f} {:<10.5f} {:<10.5f} {:<10.5f}".format(n, x, yanal, yeuler5, yeuler1, yrk2, yrk4, yscp))
print('')

data = [ylist_euler5, ylist_euler1nw, ylist_RK2, ylist_RK4, yscipy]
eps = []
k = 0
for i in data:
  epslist = []
  n = 0
  for j in i:
    epsilon = np.abs((j - ylistanl[n])/ylistanl[n])
    epslist.append(epsilon)
    n += 1
  eps.append(epslist)
  k += 1