I would like to implement my own basic Runge-Kutta 4 integrator in Python. The format should be something like this:
---- EXAMPLE set of equations ----
f1 = lambda x: x**2
f2 = lambda y: y**2
.
.
.
fn = lambda n: n**2
f = [f1, f2, f3, ... , fn]
result = integrate(f, other arguments [e.g. stepsize etc.])
---- result should be of format ----
result = [result1 result2 result3 ... resultn]
So basically I want to be able to define, for example, a set of three equations of motion, and be able to pass these to a function and access them to manipulate these equations inside of that function. How is that possible?
Ideally, I want to achive something similar to Matlabs ode45 function, which can be called for example as follows:
% ---- file 1 ---- %
function xp=F(t,x)
xp=zeros(2,1);
xp(1)=x(2);
xp(2)=-t*x(1)+exp(t)*x(2)+3*sin(2*t);
% ---- file 2 ---- %
[t,x]=ode45(’file 1’,[t0,tf],[x10,x20]);
% where t0 tf initial and final values of t
% x10 x20 initial values of x
Note 1:
I have already looked at the source for dopri5 in SciPy but it is implemented in C and far too advanced for my purposes.
Note 2:
Let me know if what I've written above is not clear at all, which