Re: NDSolve, delta functions, strategy and speed
- To: mathgroup at smc.vnet.net
- Subject: [mg42795] Re: NDSolve, delta functions, strategy and speed
- From: "Kevin J. McCann" <KevinMcCann!kjm at uunet.uu.net>
- Date: Wed, 30 Jul 2003 04:07:21 -0400 (EDT)
- References: <bfrk9s$rfc$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
I am not sure how to speed this up; however, I think you should replace res = {res,{x0,v0}} with AppendTo[res,{x0,v0}] The former leads to some kind of weird recursive result. Cheers, Kevin "Goyder Dr HGD" <H.Goyder at rmcs.cranfield.ac.uk> wrote in message news:bfrk9s$rfc$1 at smc.vnet.net... > Dear MathGroup, > > I am applying a sequence of random delta functions to a system. The delta > functions are applied periodically with a period of ts. > I use NDSolve to work out the response following each delta function, > determine the final conditions, modify them by adding the delta function and > then reuse them as initial conditions for the next period. > > Here are the random amplitudes for the delta function > > ii = 10000; ts = 0.001; > ran = Table[Random[] - 0.5, {i, ii}]; > > and this is my solution for a simple test case. > > Timing[ > {x0, v0} = {0, ran[[1]]}; > res = {{x0, v0}}; > Do[ {x0, v0} = {x[ts], v[ts]} /. First[NDSolve[ > {x'[t] == v[t], v'[t] == -0.1 > Pi v[t] - 4Pi^2 (x[t] + 10 x[t]^3), x[0] == x0, v[0] == v0}, > {x, v}, {t, 0, ts}]]; > v0 = v0 + ran[[i]]; res = {res, {x0, v0}}, {i, 2, ii}]] > > This works but is slow. Are there better methods? > > Thanks > > Hugh Goyder > >