       Re: Vector Runge-Kutta ODE solver with compilation?

• To: mathgroup at smc.vnet.net
• Subject: [mg116837] Re: Vector Runge-Kutta ODE solver with compilation?
• From: DmitryG <einschlag at gmail.com>
• Date: Wed, 2 Mar 2011 04:33:02 -0500 (EST)
• References: <ikihnp\$7sm\$1@smc.vnet.net>

```Dear Oliver and Daniel,

Vectorizing RHS is a magic trick that did the job, thank you a lot!
Now the compiled code is short and its length does not depend on NN.
The execution time strongly decreased, as one can expect from vector
operations. I can also compile in C without problems. Strangely, the
execution time is longer in the case of compilation in C!

I hope I will be able to do vectorization for my real problem where
RHS is similar but more complicated.

Another idea is to do vectorization for NDSolve. I have always
generated equations as Lists such as Equations=Table[...] but maybe I
could completely vectorize NDSolve and achieve a great speed? I have
tried with the system of equations we are discussing

******************************************************************************

NN = 100;        tMax = 50;
x0 = Table[RandomReal[{0, 1}], {i, 1, NN}];
Equations = x'[t] == - x[t]/(1 + 300 Total[x[t]]^2/NN^2);

Timing[Solution = NDSolve[{Equations, x == x0}, x, {t, 0, tMax},
MaxSteps -> 1000000]]

x1t[t_] := x[t][] /. Solution[];
x2t[t_] := x[t][] /. Solution[];
x3t[t_] := x[t][] /. Solution[];
Plot[{x1t[t], x2t[t], x3t[t]}, {t, 0, tMax}, PlotStyle -> {Red, Green,
Blue}]

**********************************************************************************

but this is not working. Probably Mathematica does not understand that
x[t] is a vector? How to fix the problem?