       NDSolve useless?

• To: mathgroup at smc.vnet.net
• Subject: [mg63821] NDSolve useless?
• From: Alberto Verga <Alberto.Verga at laposte.net>
• Date: Sun, 15 Jan 2006 05:43:33 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

Hi,
The following code takes above a minute CPU time (it solves a set of coupled
ordinary differential equations):
In:=
\!\(\(NV = 128;\)\[IndentingNewLine]
\(tf = 1. ;\)\[IndentingNewLine]
\(\[Delta] = 0.1;\)\[IndentingNewLine]
\(a = 0.01;\)\[IndentingNewLine]
\(x0 = Table[
n/NV + a\ Sin[2 \[Pi]\ n/NV], {n, 1, NV}];\)\[IndentingNewLine]
\(y0 = Table[\(-a\)\ Sin[2 \[Pi]\ n/NV], {n, 1, NV}];\)\[IndentingNewLine]
\(difx = 2 \[Pi]\ \((x\_n[t] - x\_m[t])\);\)\[IndentingNewLine]
\(dify = 2 \[Pi] \((y\_n[t] - y\_m[t])\);\)\[IndentingNewLine]
\(deno =
2\ NV \((Cosh[dify] - Cos[difx] + \[Delta]\^2)\);\)\[IndentingNewLine]
\(equx = \(-Sinh[dify]\)/deno;\)\[IndentingNewLine]
\(equy = Sin[difx]/deno;\)\[IndentingNewLine]
\(sol =
NDSolve[Flatten[
Table[{\[IndentingNewLine]D[x\_n[t], t] ==
Sum[equx, {m, 1, NV}], \[IndentingNewLine]D[y\_n[t], t] ==
Sum[equy, {m, 1, NV}], \[IndentingNewLine]x\_n ==
x0[\([n]\)], \[IndentingNewLine]y\_n ==
y0[\([n]\)]}, {n, 1, NV}]], \[IndentingNewLine]Flatten[
Table[{x\_n, y\_n}, {n, 1, NV}]], \[IndentingNewLine]{t, 0,
tf}];\) // Timing\)
Out=
{76.199 Second, Null}

The same problem solved with function ode45 (or compiled in C or fortran),
takes about (less than) 1 second (on
the same computer). Is there a way to optimize this kind of *numerical*
computation in Mathematica? Or is NDSolve useless?

(Remark: my question is not about computers but about the implementation of
NDSolve, compared for exemple with other numerical packages; if you add
Method->ExplicitRungeKutta, timing increases!)

Alberto Verga

Alberto Verga

IRPHE - Université de Provence
49, rue F. Joliot-Curie, BP 146,
13384 Marseille, France
Tél: 33 (0) 496139751 Fax: 33 (0) 496139709

• Prev by Date: Re: mac os x 10.4.4 breaks mathematica 5.2 (again)
• Next by Date: Re: Re: Can anybody help?
• Previous by thread: Re: FindInstance
• Next by thread: Re: NDSolve useless?