MathGroup Archive 1999

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

Search the Archive

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[0]==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[10] or  pFunction[t].

______________________
REMARK:

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.


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

In[2]:=
pFunction[t_]:=Evaluate[(P[t]/. DSolve[{P'[t]==0.031P[t], P[0]==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[3]:=
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
  • Next by thread: Mathlink Wantabe