Skip to content

Added adams-bashforth method of order 2, 3, 4, 5 #10969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 28, 2023
Prev Previous commit
Update adams_bashforth.py
  • Loading branch information
cclauss authored Oct 28, 2023
commit 0703b9ca40c0254f289f59cca269473b062f03e3
15 changes: 2 additions & 13 deletions maths/numerical_analysis/adams_bashforth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Use the Adams-Bashforth methods to solve Ordinary Differential Equations.


https://en.wikipedia.org/wiki/Linear_multistep_method
Author : Ravi Kumar
"""
Expand All @@ -25,20 +24,18 @@ class AdamsBashforth:

>>> def f(x, y):
... return x + y
>>> AdamsBashforth(f, [0, 0.2, 0.4], [0, 0.2, 1], 0.2, 1) # doctest: +ELLIPSIS
AdamsBashforth(func=..., x_initials=[0, 0.2, 0.4], y_initials=[0, 0.2, 1], step...)
>>> AdamsBashforth(f, [0, 0.2, 1], [0, 0, 0.04], 0.2, 1).step_2()
Traceback (most recent call last):
...
ValueError: The final value of x must be greater than the initial values of x.

>>> def f(x, y):
... return x + y
>>> AdamsBashforth(f, [0, 0.2, 0.3], [0, 0, 0.04], 0.2, 1).step_3()
Traceback (most recent call last):
...
ValueError: x-values must be equally spaced according to step size.

>>> def f(x, y):
... return x
>>> AdamsBashforth(f,[0,0.2,0.4,0.6,0.8],[0,0,0.04,0.128,0.307],-0.2,1).step_5()
Traceback (most recent call last):
...
Expand Down Expand Up @@ -73,8 +70,6 @@ def step_2(self) -> np.ndarray:
>>> AdamsBashforth(f, [0, 0.2], [0, 0], 0.2, 1).step_2()
array([0. , 0. , 0.06, 0.16, 0.3 , 0.48])

>>> def f(x, y):
... return (x -y)/2
>>> AdamsBashforth(f, [0, 0.2, 0.4], [0, 0, 0.04], 0.2, 1).step_2()
Traceback (most recent call last):
...
Expand Down Expand Up @@ -109,8 +104,6 @@ def step_3(self) -> np.ndarray:
>>> y[3]
0.15533333333333332

>>> def f(x, y):
... return (x -y)/2
>>> AdamsBashforth(f, [0, 0.2], [0, 0], 0.2, 1).step_3()
Traceback (most recent call last):
...
Expand Down Expand Up @@ -151,8 +144,6 @@ def step_4(self) -> np.ndarray:
>>> y[5]
0.5771083333333333

>>> def f(x, y):
... return (x -y)/2
>>> AdamsBashforth(f, [0, 0.2, 0.4], [0, 0, 0.04], 0.2, 1).step_4()
Traceback (most recent call last):
...
Expand Down Expand Up @@ -196,8 +187,6 @@ def step_5(self) -> np.ndarray:
>>> y[-1]
0.05436839444444452

>>> def f(x, y):
... return (x -y)/2
>>> AdamsBashforth(f, [0, 0.2, 0.4], [0, 0, 0.04], 0.2, 1).step_5()
Traceback (most recent call last):
...
Expand Down