Re: SIR epidemic Model
- To: mathgroup at smc.vnet.net
- Subject: [mg36275] Re: SIR epidemic Model
- From: Selwyn Hollis <slhollis at earthlink.net>
- Date: Thu, 29 Aug 2002 01:38:02 -0400 (EDT)
- References: <aki0v3$i76$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Let say you have your data in an array like so: data = {{5, {685, 12, 4}}, {10, {550, 105, 50}}, {15, {207, 250, 244}}, {20, {69, 169, 463}}} where 5, 10, 15, 20 are the observation times. (These numbers are perturbed slightly from an actual solution.) The following defines the least squares error as a function of a and b: LSE[a_, b_] := Module[ {diff, sir = {s[t],i[t],r[t]} /. NDSolve[{s'[t]== -a*s[t]*i[t], i'[t]== a*s[t]*i[t] - b*i[t], r'[t]== b*i[t], s[0]== 700, i[0]== 1, r[0]== 0}, {s[t],i[t],r[t]}, {t, 0, 20}]//First }, diff:=(sir/.t->data[[i,1]]) - data[[i,2]]; Sum[diff.diff, {i, Length[data]}] ] Now... In: FindMinimum[ LSE[a, b], {a, 0, .1}, {b, 0, 1}]//Timing Out: {5.7 sec, {14.1967, {a -> 0.000999599, b -> 0.200351}}} --- Selwyn Hollis Abdelmajid Khelil wrote: > Hi everybody, > > I solved the epidemic SIR ODE System > (<http://library.wolfram.com/webMathematica/MSP/Explore/Biology/Epidemic> > ) numerically using NDSolve: > > approxsolutions=NDSolve[{ > > s´[t]==-a s[t] i[t], > i´[t]==a s[t] i[t] - b i[t], > r´[t]==b i[t], > > s[0]==700, i[0]==1, r[0]==0}, {i[t], s[t], r[t]}, {t,0,20}]; > > and this for fixed values of a and b. > > Now I want to fit the solution for variable a and b to a list of given > points (fitting using the least squares method and the mathematica fonction > findminimum). My questions are > 1- Is it possible to solve the ODE (with mathematica) for not fixed values > of a and b (so to get a parametric solution that depends on a and b)? > 2- Is it possible in mathematica to use the fonction findminimum with the > (not explicit) solutions of the ODE, if not are there some other > alternatives? > > In advance, thank you very much > > Majid > >