maths.numerical_analysis.adams_bashforth¶
Use the Adams-Bashforth methods to solve Ordinary Differential Equations.
https://en.wikipedia.org/wiki/Linear_multistep_method Author : Ravi Kumar
Classes¶
args: |
Module Contents¶
- class maths.numerical_analysis.adams_bashforth.AdamsBashforth¶
args: func: An ordinary differential equation (ODE) as function of x and y. x_initials: List containing initial required values of x. y_initials: List containing initial required values of y. step_size: The increment value of x. x_final: The final value of x.
Returns: Solution of y at each nodal point
>>> def f(x, y): ... return x + y >>> AdamsBashforth(f, [0, 0.2, 0.4], [0, 0.2, 1], 0.2, 1) 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.
>>> 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.
>>> 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): ... ValueError: Step size must be positive.
- __post_init__() None ¶
- step_2() numpy.ndarray ¶
>>> def f(x, y): ... return x >>> AdamsBashforth(f, [0, 0.2], [0, 0], 0.2, 1).step_2() array([0. , 0. , 0.06, 0.16, 0.3 , 0.48])
>>> AdamsBashforth(f, [0, 0.2, 0.4], [0, 0, 0.04], 0.2, 1).step_2() Traceback (most recent call last): ... ValueError: Insufficient initial points information.
- step_3() numpy.ndarray ¶
>>> def f(x, y): ... return x + y >>> y = AdamsBashforth(f, [0, 0.2, 0.4], [0, 0, 0.04], 0.2, 1).step_3() >>> float(y[3]) 0.15533333333333332
>>> AdamsBashforth(f, [0, 0.2], [0, 0], 0.2, 1).step_3() Traceback (most recent call last): ... ValueError: Insufficient initial points information.
- step_4() numpy.ndarray ¶
>>> def f(x,y): ... return x + y >>> y = AdamsBashforth( ... f, [0, 0.2, 0.4, 0.6], [0, 0, 0.04, 0.128], 0.2, 1).step_4() >>> float(y[4]) 0.30699999999999994 >>> float(y[5]) 0.5771083333333333
>>> AdamsBashforth(f, [0, 0.2, 0.4], [0, 0, 0.04], 0.2, 1).step_4() Traceback (most recent call last): ... ValueError: Insufficient initial points information.
- step_5() numpy.ndarray ¶
>>> def f(x,y): ... return x + y >>> y = AdamsBashforth( ... f, [0, 0.2, 0.4, 0.6, 0.8], [0, 0.02140, 0.02140, 0.22211, 0.42536], ... 0.2, 1).step_5() >>> float(y[-1]) 0.05436839444444452
>>> AdamsBashforth(f, [0, 0.2, 0.4], [0, 0, 0.04], 0.2, 1).step_5() Traceback (most recent call last): ... ValueError: Insufficient initial points information.
- func: collections.abc.Callable[[float, float], float]¶
- step_size: float¶
- x_final: float¶
- x_initials: list[float]¶
- y_initials: list[float]¶