\(\newcommand{\B}[1]{ {\bf #1} }\) \(\newcommand{\R}[1]{ {\rm #1} }\)
py_runge_kutta¶
View page sourcePython Fourth Order Runge Kutta Method¶
Prototype¶
def runge_kutta(like_numpy, fun, yi, tf, ns) :
assert type(ns) == int
assert type(yi) == type( like_numpy.array(1.0) )
return yf
Purpose¶
This routine returns an approximate solution for \(y( t^f )\) where \(y(0) = y^i\) and \(y' (t) = f(y)\) .
like_numpy¶
This is a like_numpy class. It is used to vectorize the rk4_step algorithm.
fun¶
This is a py_fun_obj . The syntax dy = fun ( yt ) , were yt is \(y(t)\) , sets dy equal to the derivative \(y'(t)\) .
yi¶
is the value of \(y(t)\) at \(t = 0\) .
This is a vector like object with elements of type
float or Scalar .
tf¶
is the value of t at which we wish to evaluate \(y(t)\) .
This is an object of type float or Scalar .
ns¶
is the number of Runge-Kutta steps to use.
The more steps the smaller the step size and the more accurate
the solution.
This is an int .
yf¶
The return value yf has the same size as yi and is the approximation
for \(y(t)\) at t = tf .
This is a vector like object with elements of type float or Scalar .
Source Code¶
Example¶
xam_runge_kutta.py
contains an example and test of py_runge_kutta .