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"]
On 13.03.2010 13:56, Magbenji wrote:
> 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"]
>
--
Daniel Huber
Metrohm Ltd.
Oberdorfstr. 68
CH-9100 Herisau
Tel. +41 71 353 8585, Fax +41 71 353 8907
E-Mail:<mailto:d...@metrohm.com>
Internet:<http://www.metrohm.com>