       RE: Re: question

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

```Fabien Boniver  gave the solution below, and I think it deserves a
closer look.
______________________
FABIEN'S SOLUTION:

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==5.3},
P[t],t][[1,1]])/.t->s

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

______________________
REMARK:

Sure but then if you evaluate
Map[pFunction, Range] 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.

In:=
pFunction[t_]=(P[t]/. DSolve[{P'[t]==0.031P[t], P==5.3},
P[t],t][[1,1]]);

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

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.

In:=
Plot[pFunction[x],{x,0,100}];

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.

Cheers,
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