Re: NDSolve useless?
- To: mathgroup at smc.vnet.net
- Subject: [mg63830] Re: NDSolve useless?
- From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
- Date: Tue, 17 Jan 2006 04:33:25 -0500 (EST)
- Organization: Uni Leipzig
- References: <dqd9oi$mc5$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, the numerical methods in NDSolve[] are much better than ode45 can ever be. There is clearly some over head when Mathematica preprocess the equations and store an interpolating function ... Regards Jens "Alberto Verga" <Alberto.Verga at laposte.net> schrieb im Newsbeitrag news:dqd9oi$mc5$1 at smc.vnet.net... | Hi, | The following code takes above a minute CPU time (it solves a set of coupled | ordinary differential equations): | In[13]:= | \!\(\(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[0] == | x0[\([n]\)], \[IndentingNewLine]y\_n[0] == | y0[\([n]\)]}, {n, 1, NV}]], \[IndentingNewLine]Flatten[ | Table[{x\_n, y\_n}, {n, 1, NV}]], \[IndentingNewLine]{t, 0, | tf}];\) // Timing\) | Out[24]= | {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 | | | |