-
Notifications
You must be signed in to change notification settings - Fork 0
/
metode_euler.py
44 lines (37 loc) · 1.02 KB
/
metode_euler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from solver import *
def cauchy_euler(params,Func):
# Initial Condition
t0 = params['t0']
t_akhir = params['t_akhir']
h = params['h']
y0 = params['y0']
dy0 = params['dy0']
res_euler = []
t = []
step = int((t_akhir - t0) / h)
for i in range(step):
tm = (i + 1) * h
(y_next, dy_next) = euler(tm, h, y0, dy0, Func)
res_euler.append(y_next)
t.append(tm)
y0 = y_next
dy0 = dy_next
return (t,res_euler)
def cauchy_eulercromer(params,Func):
# Initial Condition
t0 = params['t0']
t_akhir = params['t_akhir']
h = params['h']
y0 = params['y0']
dy0 = params['dy0']
res_euler_cromer = []
t = []
step = int((t_akhir - t0) / h)
for i in range(step):
tm = (i + 1) * h
(y_next, dy_next) = euler_cromer(tm, h, y0, dy0, Func)
res_euler_cromer.append(y_next)
t.append(tm)
y0 = y_next
dy0 = dy_next
return (t, res_euler_cromer)