1
1
"""
2
2
Use the Adams-Bashforth methods to solve Ordinary Differential Equations.
3
3
4
-
5
4
https://en.wikipedia.org/wiki/Linear_multistep_method
6
5
Author : Ravi Kumar
7
6
"""
@@ -25,20 +24,18 @@ class AdamsBashforth:
25
24
26
25
>>> def f(x, y):
27
26
... return x + y
27
+ >>> AdamsBashforth(f, [0, 0.2, 0.4], [0, 0.2, 1], 0.2, 1) # doctest: +ELLIPSIS
28
+ AdamsBashforth(func=..., x_initials=[0, 0.2, 0.4], y_initials=[0, 0.2, 1], step...)
28
29
>>> AdamsBashforth(f, [0, 0.2, 1], [0, 0, 0.04], 0.2, 1).step_2()
29
30
Traceback (most recent call last):
30
31
...
31
32
ValueError: The final value of x must be greater than the initial values of x.
32
33
33
- >>> def f(x, y):
34
- ... return x + y
35
34
>>> AdamsBashforth(f, [0, 0.2, 0.3], [0, 0, 0.04], 0.2, 1).step_3()
36
35
Traceback (most recent call last):
37
36
...
38
37
ValueError: x-values must be equally spaced according to step size.
39
38
40
- >>> def f(x, y):
41
- ... return x
42
39
>>> AdamsBashforth(f,[0,0.2,0.4,0.6,0.8],[0,0,0.04,0.128,0.307],-0.2,1).step_5()
43
40
Traceback (most recent call last):
44
41
...
@@ -73,8 +70,6 @@ def step_2(self) -> np.ndarray:
73
70
>>> AdamsBashforth(f, [0, 0.2], [0, 0], 0.2, 1).step_2()
74
71
array([0. , 0. , 0.06, 0.16, 0.3 , 0.48])
75
72
76
- >>> def f(x, y):
77
- ... return (x -y)/2
78
73
>>> AdamsBashforth(f, [0, 0.2, 0.4], [0, 0, 0.04], 0.2, 1).step_2()
79
74
Traceback (most recent call last):
80
75
...
@@ -109,8 +104,6 @@ def step_3(self) -> np.ndarray:
109
104
>>> y[3]
110
105
0.15533333333333332
111
106
112
- >>> def f(x, y):
113
- ... return (x -y)/2
114
107
>>> AdamsBashforth(f, [0, 0.2], [0, 0], 0.2, 1).step_3()
115
108
Traceback (most recent call last):
116
109
...
@@ -151,8 +144,6 @@ def step_4(self) -> np.ndarray:
151
144
>>> y[5]
152
145
0.5771083333333333
153
146
154
- >>> def f(x, y):
155
- ... return (x -y)/2
156
147
>>> AdamsBashforth(f, [0, 0.2, 0.4], [0, 0, 0.04], 0.2, 1).step_4()
157
148
Traceback (most recent call last):
158
149
...
@@ -196,8 +187,6 @@ def step_5(self) -> np.ndarray:
196
187
>>> y[-1]
197
188
0.05436839444444452
198
189
199
- >>> def f(x, y):
200
- ... return (x -y)/2
201
190
>>> AdamsBashforth(f, [0, 0.2, 0.4], [0, 0, 0.04], 0.2, 1).step_5()
202
191
Traceback (most recent call last):
203
192
...
0 commit comments