Re: NDSolve useless?
- To: mathgroup at smc.vnet.net
- Subject: [mg63883] Re: [mg63821] NDSolve useless?
- From: <bsyehuda at gmail.com>
- Date: Fri, 20 Jan 2006 04:32:38 -0500 (EST)
- References: <200601151043.FAA22735@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, I tested your case as well. I wonder HOW LONG it will take you to program the representation of the problem (FORTRAN, C ?) comparing to the time it takes with Mathematica. I believe that most program that are intended to do A SINGLE task will perform faster then Mathematica, but however they are by far less appropriate for the general case. Do not forget that Mathematica also uses complicated decision process to determine which numerical solution method is best to the specific case (and I suspect that ode45 is not) Mathematica also returns the answer in terms of InterpolationFunction[] and you may use it as any other continuous function in the given range (and I suspect ode45 is not, but I don't really know that fo sure). So, summing 1. Programming time to represent the problem 2. The run time 3. programming time to represent the results to get an interpolated expressions (0 time with Mathematica) 4. run time for the interpolation I suspect that Mathematica will win, since steps 1 and 3 are implemented manually in most cases. I must add that in the past I used to (as most people) put a lot of effort so the computer will have a FAST program. This approach usually cut few seconds to few hours of CPU time. The time to program this improvements usually takes MUCH longer. So after becoming older (and wiser, perhaps) it worth to pay more time in steps 2 and 4 and let the computer work harder. This is however my personal humble opinion. regards yehuda On 1/15/06, Alberto Verga <Alberto.Verga at laposte.net> wrote: > > 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 - Universite de Provence > 49, rue F. Joliot-Curie, BP 146, > 13384 Marseille, France > T=E9l: 33 (0) 496139751 Fax: 33 (0) 496139709 > > > > >
- References:
- NDSolve useless?
- From: Alberto Verga <Alberto.Verga@laposte.net>
- NDSolve useless?