Re: Help with NDSolve

*To*: mathgroup at christensen.cybernetics.net*Subject*: [mg1541] Re: Help with NDSolve*From*: rknapp (Robert Knapp)*Date*: Sat, 24 Jun 1995 02:37:25 -0400*Organization*: The Santa Fe Institute

In article <3s86l4$och at news0.cybernetics.net> imm at cs.umd.edu (Ibrahim Matta) writes: > I am trying to solve a differential equation > NN'[t] = lambda ( 1 - B[t] ) - mu NN[t] > where B[t] is a fixed point of a function of NN[t] and B[t]. > > The program below does not, however, terminate. > It works if we use Nest instead of FixedPoint, but > we need FixedPoint for the stopping criteria. > I suspect that with FixedPoint Mathematica can not > symbolically get the differential equations. > Is there a way around this or it can't be done with > Mathematica ? > > Any help is very much appreciated. > > Best regards, > Ibrahim > > ============================================= > > T = 20 > lambda = 0.8 > mu = 1.0 > K = 2 > > Clear[NN] > Clear[B] > > > B[b_] := (NN[t] / (1 - b))^K / K! / > (1 + Sum[(NN[t] / (1 - b))^ii / ii!, {ii, K}]) > > > > > sol = NDSolve[{NN'[t] == > lambda (1 - FixedPoint[B, 0.1, SameTest->(Abs[#1 - #2] < 10.^-4 &)]) > - mu NN[t], NN[0] == 0}, > NN, {t, T}] > > Plot[Evaluate[NN[t] /. sol], {t, 0, T}] > > ============================================= Your problem here is that NDSolve evaluates the equation before solving the equations. You will find that if you simply evaluate {NN'[t] == lambda (1 - FixedPoint[B, 0.1, SameTest->(Abs[#1 - #2] < 10.^-4 &)]) - mu NN[t], NN[0] == 0} by itself, the FixedPoint does not terminate because the condition is never met with a symbolic N[t]. The solution (generally a good one in any case like this where non-numeric evaluation is dangerous) is to prevent symbolic evaluation. Here is a fix: define a new function: FixPointB[val_?NumberQ] := FixedPoint[B[val], 0.1, SameTest->(Abs[#1 - #2] < 10.^-4 &)] this tests the argument "val" to be sure that it is a number before attempting FixedPoint. Using this function and your other definitions, the call to NDSolve: In[17]:= sol = NDSolve[{NN'[t] == lambda (1 - FixPointB[NN[t]]) - mu NN[t], NN[0] == 0}, NN, {t, T}] Out[17]= {{NN -> InterpolatingFunction[{0., 20.}, <>]}} works as it should. Rob Knapp WRI