This node assumes some basic knowledge and terminology of differential equations. It also assumes that you are actually care at least a little bit about them. If this is not the case, I recommend that you go and read something about monkeys or ninjas instead.
You've got your fancy numerical 1st order ordinary differential equation solver working, for example by using Euler's method or a 4th order Runge Kutta method. You can solve equations of the form y'=f(x,y) and all is well. But one day you tire of first order equations (a sad but inevitable fate) and, filled by a desire for greater glory, wish to solve second order equations.
Do not give up hope! You can use your first order methods to solve second order ordinary differential equations, with help of a little trick.
The trick is to somehow turn the nasty tricksy second order equation into a nice first order one that your numerical solver can chew on. Impossible you say? The trick is in fact to make the unknown a vector of 2 functions, instead of just a single function. This yields a first order equation.
Lets say we start of with the equation y''=f(x,y,y'), and f is a function of x, y and y'. We also have the boundary conditions that your numerical solver will need, i.e. the value of y and its derivative at a given point.
We define z =y', then the initial equation becomes:
In other words, our unknown is the vector
v=(y,z). If we define F(x,y,z) to be the vector
of functions (z,f(x,y,z))
, then our equation is v'=F(x,v).
Now the equation we've obtained isn't very nice. In fact if you were solving analytically you tend to start off with such a vector equation and decouple it to obtain the second order equation we started with. But right now we're dealing with numerical solutions, and our numerical solver doesn't really care what the particulars of the functions it has to deal with. And v'=F(x,v) looks very similar to the type of equation that your solver is used to dealing with.
So you want to actually use this?
This is really quite simple. Basically everywhere where you had a floating point number, used to represent the value of the solution at a given point, you will instead have a vector of values. You will probably need some functions to add these vectors together and multiply them by a scalar. When you finished solving the first order equation you simply pull out the y component from your solution vector and you have the answer to the original problem.
Apart from that your code needs no changes! And once you've switched your code over to using vectors then you can very easily turn it into a solver for higher order equations, using the same basic idea. I wish you many hours of happiness.