MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Re: question

  • To: mathgroup at
  • Subject: [mg15683] RE: [mg15612] Re: question
  • From: "Ersek, Ted R" <ErsekTR at>
  • Date: Sun, 31 Jan 1999 03:06:06 -0500 (EST)
  • Sender: owner-wri-mathgroup at

Fabien Boniver  gave the solution below, and I think it deserves a
closer look.

You can put  the result in a working function pFunction (or any other
name, of course) like this :

pFunction[s_]:=(P[t]/. DSolve[{P'[t]==0.031P[t], P[0]==5.3},

You can then compute explicit values of pFunction, the solution of your
diff. eq., like pFunction[10] or  pFunction[t].


Sure but then if you evaluate 
Map[pFunction, Range[50]] your pFunction will solve the DiffEq 50 times.
It also evaluates (expr[[1,1]]) 50 times and make the replacement t->s 
50 times.

It's much more efficient to evaluate the right side once (when pFunction
is defined).  Also there is no need to change from (t) to (s).  Either
of the lines below will do this nicely.  The first approach uses (=)
instead of (:=) which evaluates the right side immediately.

pFunction[t_]=(P[t]/. DSolve[{P'[t]==0.031P[t], P[0]==5.3},

pFunction[t_]:=Evaluate[(P[t]/. DSolve[{P'[t]==0.031P[t], P[0]==5.3},

For all practical purposes the two above are equivalent (I think). 
Using either definition above Plot (as in the line below) works faster
that the earlier solution by orders of magnitude.


As I discussed in my earlier post on this subject the lines above will
not have the desired result if (t) has a global value.

Ted Ersek

  • Prev by Date: Re: Button to delete all graphics
  • Next by Date: 4th order DE, NDSolve no solution, why?
  • Previous by thread: Re: question
  • Next by thread: Mathlink Wantabe