Re: Plot not working correctly
- To: mathgroup at smc.vnet.net
- Subject: [mg108350] Re: Plot not working correctly
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sun, 14 Mar 2010 05:16:34 -0500 (EST)
You used x inside the definition of ar[ ] without localizing it to the Module. This conflicts with the x used in the Plot.
Bob Hanlon
---- Magbenji <ben.ridenhour at gmail.com> wrote:
=============
Hello, I'm having a problem with plotting and I'm not sure what the
cause of it is. What is going on???
Here is what I'm doing:
(*A simple system of ODEs*)
dS[t_]:= -b/P*S[t]*Inf[t]
dInf[t_]:=b/P*S[t]*Inf[t]-g*Inf[t]
dR[t_]:=g*Inf[t]
(*A function to solve the system and return the value of R[100000]*)
ar[r_,s_,pop_]:=Module[{parms,solution},
parms={P->pop,b->r,g->s};
solution=
NDSolve[{S'[t]==dS[t],Inf'[t]==dInf[t],R'[t]==dR[t],S[0]==P-1,Inf[0]==1,R[0]==0}/.parms,
{S,Inf,R},{t,0,100000}];
(R[x]/pop /.solution /. x->100000)[[1]]
]
(*Use ListPlot to look at values; works correctly*)
ListPlot[Table[{i,ar[0.1,i,10000]},{i,0,0.1,0.001}],PlotLabel-
>"CORRECT"]
(*Now try it using Plot; WRONG PLOT*)
Plot[ar[0.1,x,10000],{x,0,0.1}, PlotLabel->"INCORRECT"]
--
Bob Hanlon