Since the consensus is usually that NDSolve speeds fares badly against compiled code such as c++ ODE solvers using GSL say, is it possible to make up for this lag by using Mathematica's Compile functionality? Somehow compiling your ODE to make it execute quicker or some such?
If not is there a way to use something like MathLink?
And finally, is it really true that c++ ODE solvers outperform Mathematica 8 NDSolve in terms of speed?
Answer
I'm sorry, I though someone had already give you a hint about this. Let me give you a short example: You surely know that you can transform your differential equation into a system of deq of order 1. If you do this, you get the form
$$y'(t)=f(y,t)$$
When the right hand side is very complex it might worth to compile it. I'm not sure to which point this is maybe already done by Mathematica. Therefore, you should really investigate in this issue before using it.
Here is the first example from the NDsolve help page:
s = NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}];
Plot[Evaluate[y[x] /. s], {x, 0, 30}, PlotRange -> All]

Now I compile the rhs and use it exactly in the same way:
f = Compile[{{x, _Real}, {yx, _Real}}, yx Cos[x + yx]];
rhs[x_?NumericQ, yx_?NumericQ] := f[x, yx];
s2 = NDSolve[{y'[x] == rhs[x, y[x]], y[0] == 1}, y, {x, 0, 30}];
Plot[Evaluate[y[x] /. s2], {x, 0, 30}, PlotRange -> All]

Comments
Post a Comment