Re: NDSolve

*To*: mathgroup at smc.vnet.net*Subject*: [mg8591] Re: [mg8536] NDSolve*From*: David Withoff <withoff>*Date*: Sun, 7 Sep 1997 22:13:10 -0400*Sender*: owner-wri-mathgroup at wolfram.com

> I wonder why the following did not work. > > NDSolve[{q'[k]==If[k==kss,qprimess,kdotfun/qdotfun],q[kss]=qss},... > *************** > The trouble is here. > > kdotfun and qdotfun are both defined previously as functions of [k]. > The error message was like > > ...does not evaluate at 34.5444 <-this is the value for kss ... > > When I just typed in the same function instead of using 'kdotfun/qdotfun', > it worked. But I would rather not like to do it because the expression for > it is sometimes quite complicated. Probably the easiest way to get this to work is to use Evaluate around the expression that is defined as a function of k, as in In[1]:= kss = 1; qprimess = 1; kdotfun = k; qdotfun = 1; qss = 1; General::spell1: Possible spelling error: new symbol name "qdotfun" is similar to existing symbol "kdotfun". In[2]:= sol = NDSolve[{q'[k]==If[k==kss,qprimess, Evaluate[kdotfun/qdotfun]],q[kss]==qss}, q, {k, 1, 2}] Out[2]= {{q -> InterpolatingFunction[{{1., 2.}}, <>]}} The NDSolve function does a limited form of variable localization, which means among other things that the variable needs to appear explicitly in the input to NDSolve. > I have one more question. > I Plot the InterpolatingFunction and want to mark a point of the line with > * or else. Can I do this? Yes, you can do this. One method is to use a graphics primitive to put a mark at the point that you want. For example: In[4]:= Show[g, Graphics[{PointSize[.02], Point[{1.6, q[1.6] /. sol[[1]]}]}]] Out[4]= -Graphics- Dave Withoff Wolfram Research