maths.numerical_analysis.runge_kutta_gills

Use the Runge-Kutta-Gill’s method of order 4 to solve Ordinary Differential Equations.

https://www.geeksforgeeks.org/gills-4th-order-method-to-solve-differential-equations/ Author : Ravi Kumar

Functions

runge_kutta_gills(→ numpy.ndarray)

Solve an Ordinary Differential Equations using Runge-Kutta-Gills Method of order 4.

Module Contents

maths.numerical_analysis.runge_kutta_gills.runge_kutta_gills(func: collections.abc.Callable[[float, float], float], x_initial: float, y_initial: float, step_size: float, x_final: float) numpy.ndarray

Solve an Ordinary Differential Equations using Runge-Kutta-Gills Method of order 4.

args: func: An ordinary differential equation (ODE) as function of x and y. x_initial: The initial value of x. y_initial: The initial value 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)/2
>>> y = runge_kutta_gills(f, 0, 3, 0.2, 5)
>>> float(y[-1])
3.4104259225717537
>>> def f(x,y):
...     return x
>>> y = runge_kutta_gills(f, -1, 0, 0.2, 0)
>>> y
array([ 0.  , -0.18, -0.32, -0.42, -0.48, -0.5 ])
>>> def f(x, y):
...     return x + y
>>> y = runge_kutta_gills(f, 0, 0, 0.2, -1)
Traceback (most recent call last):
    ...
ValueError: The final value of x must be greater than initial value of x.
>>> def f(x, y):
...     return x
>>> y = runge_kutta_gills(f, -1, 0, -0.2, 0)
Traceback (most recent call last):
    ...
ValueError: Step size must be positive.