Fitting Parameters of ODE to Experimental Data SIR Model
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Shawn Cooper
am 28 Jul. 2020
Kommentiert: Alan Stevens
am 1 Jun. 2022
Using observed data for the values S, I, and R, I am trying to solve for the parameters β and γ given by the simple SIR Model:
β and γ are represented by the parameter vector p and the values of S, I, and R are represented by vector y.
My ODE function to match the above equations is:
function dydt = odefun(t,y,p)
dydt = zeros(3,1);
p = zeros(2,1);
dydt(1) = -p(1) * y(1) * y(2);
dydt(2) = p(1) * y(1) * y(2) - p(2) * y(2);
dydt(3) = p(2) * y(2);
end
My least-squares function is:
function err = odefit(exp_t,exp_y,p)
[t,y] = ode45(@(t,y)odefun(t,y,p),exp_t,[1 1/5072000 0]); %initial conditions w/ 1 infected (i)
err = sum((y-exp_y).^2);
end
Given observed values of y (exp_y) at times t (exp_t) [I've made these variables available at the end of the question if needed], I set:
exp_y = [s; i; r];
exp_t = 1:length(i);
p0 = [0.341 0.141]; %initial guess for beta and gamma, based on real world data
My estimate for the parameters is then:
p_estimate = fminsearch(@(p)odefit(exp_t,exp_y,p),p0);
I am getting a matrix dimensions must agree error in my odefit function.
My assumption is that I've made some kind of mistake in defining odefun, as I'm used to doing so with known constants instead of unknown constants. Any advice on how to proceed is appreciated, thanks!
----
My values for s, i, and r, if needed:
s = 0.999999802839117 0.999999408517350 0.999999605678233 0.999999408517350 0.999999605678233 0.999999605678233 0.999999408517350 0.999999408517350 0.999999211356467 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999998817034700 0.999998817034700 0.999998817034700 0.999998817034700 0.999998817034700 0.999998817034700 0.999998817034700 0.999998817034700 0.999998028391167 0.999998028391167 0.999998028391167 0.999997634069401 0.999997634069401 0.999995859621451 0.999995859621451 0.999995859621451 0.999995465299685 0.999995465299685 0.999994873817035 0.999994479495268 0.999994479495268 0.999991522082019 0.999989353312303 0.999986395899054 0.999985015772871 0.999983044164038 0.999979889589905 0.999970031545741 0.999962145110410 0.999954850157729 0.999947358044164 0.999935528391167 0.999920149842271 0.999911080441640 0.999901025236593 0.999888801261830 0.999875000000000 0.999868690851735 0.999862184542587 0.999851537854890 0.999844045741325 0.999833004731861 0.999825512618297 0.999820189274448 0.999818809148265 0.999783517350158 0.999780954258675 0.999779179810726 0.999743296529968 0.999735607255521 0.999733635646688 0.999731861198738 0.999731072555205 0.999715102523659 0.999714905362776 0.999714511041010 0.999713328075710 0.999653194006309 0.999652405362776 0.999652405362776 0.999651419558360 0.999651419558360 0.999651025236593 0.999651025236593 0.999638209779180 0.999613170347003 0.999612578864353 0.999610804416404 0.999609227129338 0.999608241324921 0.999604692429022 0.999602326498423 0.999600946372240 0.999599960567823 0.999598974763407 0.999597791798107 0.999596805993691 0.999591876971609 0.999591876971609 0.999591482649842 0.999589116719243 0.999588722397476 0.999588525236593 0.999587736593060 0.999586553627760 0.999586356466877 0.999585764984227 0.999585567823344 0.999585173501577 0.999585173501577 0.999585173501577 0.999584582018927 0.999584384858044 0.999585962145110 0.999585567823344 0.999584187697161 0.999583990536278 0.999583990536278 0.999583990536278 0.999583793375394 0.999583793375394 0.999583399053628 0.999583596214511 0.999583596214511 0.999583004731861 0.999582807570978 0.999582610410095 0.999582413249211 0.999582216088328 0.999582216088328 0.999582018927445 0.999581821766562 0.999581624605678 0.999581624605678 0.999581624605678 0.999581624605678 0.999581230283912 0.999581230283912 0.999581033123028 0.999581033123028 0.999581033123028 0.999581033123028 0.999581033123028 0.999581033123028 0.999580835962145 0.999580638801262 0.999580638801262 0.999580638801262 0.999580638801262 0.999580638801262 0.999580638801262 0.999580638801262 0.999580638801262 0.999580441640379 0.999580441640379 0.999580441640379 0.999580244479495 0.999580047318612 0.999579850157729 0.999579850157729 0.999579258675079 0.999579258675079 0.999579061514196 0.999579061514196 0.999579061514196 0.999579061514196 0.999579061514196 0.999578864353312 0.999578667192429 0.999578272870663 0.999578272870663 0.999577878548896 0.999577484227129 0.999577089905363 0.999577089905363 0.999577089905363 0.999577089905363 0.999577089905363
i = 1.97160883280757e-07 5.91482649842271e-07 3.94321766561514e-07 5.91482649842271e-07 3.94321766561514e-07 3.94321766561514e-07 5.91482649842271e-07 5.91482649842271e-07 7.88643533123028e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 7.88643533123028e-07 7.88643533123028e-07 7.88643533123028e-07 7.88643533123028e-07 7.88643533123028e-07 7.88643533123028e-07 7.88643533123028e-07 7.88643533123028e-07 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.97160883280757e-06 1.97160883280757e-06 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 1.38012618296530e-06 1.38012618296530e-06 1.97160883280757e-06 2.36593059936909e-06 2.36593059936909e-06 5.32334384858044e-06 7.49211356466877e-06 1.04495268138801e-05 1.18296529968454e-05 1.38012618296530e-05 1.69558359621451e-05 2.68138801261830e-05 3.47003154574132e-05 4.19952681388013e-05 4.94873817034700e-05 6.13170347003155e-05 7.66955835962145e-05 8.57649842271293e-05 9.54258675078864e-05 0.000107649842271293 0.000121451104100946 0.000127365930599369 0.000133872239747634 0.000144518927444795 0.000152011041009464 0.000162263406940063 0.000169755520504732 0.000175078864353312 0.000176458990536278 0.000146687697160883 0.000149250788643533 0.000151025236593060 0.000119085173501577 0.000116127760252366 0.000117705047318612 0.000119479495268139 0.000120268138801262 0.000108635646687697 0.000108832807570978 0.000109227129337539 0.000110410094637224 5.34305993690852e-05 5.42192429022082e-05 5.42192429022082e-05 5.52050473186120e-05 5.52050473186120e-05 5.55993690851735e-05 5.55993690851735e-05 4.27839116719243e-05 1.93217665615142e-05 1.99132492113565e-05 1.85331230283912e-05 1.65615141955836e-05 1.55757097791798e-05 1.24211356466877e-05 1.04495268138801e-05 1.02523659305994e-05 1.12381703470032e-05 1.02523659305994e-05 9.85804416403786e-06 8.87223974763407e-06 3.94321766561514e-06 3.94321766561514e-06 3.54889589905363e-06 3.54889589905363e-06 3.54889589905363e-06 2.95741324921136e-06 3.35173501577287e-06 2.56309148264984e-06 2.36593059936909e-06 2.56309148264984e-06 2.36593059936909e-06 2.36593059936909e-06 2.36593059936909e-06 2.36593059936909e-06 2.56309148264984e-06 2.76025236593060e-06 2.36593059936909e-06 2.36593059936909e-06 1.38012618296530e-06 1.18296529968454e-06 1.18296529968454e-06 1.18296529968454e-06 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 1.18296529968454e-06 1.57728706624606e-06 9.85804416403786e-07 1.18296529968454e-06 9.85804416403786e-07 1.18296529968454e-06 9.85804416403786e-07 9.85804416403786e-07 1.18296529968454e-06 1.38012618296530e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.18296529968454e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.18296529968454e-06 1.18296529968454e-06 1.18296529968454e-06 1.38012618296530e-06 1.18296529968454e-06 9.85804416403786e-07 9.85804416403786e-07 1.18296529968454e-06 1.18296529968454e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.18296529968454e-06 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06
r = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.77444794952681e-06 1.77444794952681e-06 1.77444794952681e-06 1.97160883280757e-06 1.97160883280757e-06 1.97160883280757e-06 1.97160883280757e-06 2.36593059936909e-06 2.36593059936909e-06 2.36593059936909e-06 2.36593059936909e-06 3.48974763406940e-05 3.48974763406940e-05 3.48974763406940e-05 6.88091482649842e-05 7.41324921135647e-05 7.43296529968454e-05 7.43296529968454e-05 7.43296529968454e-05 8.81309148264984e-05 8.81309148264984e-05 8.81309148264984e-05 8.81309148264984e-05 0.000146687697160883 0.000146687697160883 0.000146687697160883 0.000146687697160883 0.000146687697160883 0.000146687697160883 0.000146687697160883 0.000159503154574132 0.000183753943217666 0.000183753943217666 0.000185331230283912 0.000187105678233438 0.000188091482649842 0.000191443217665615 0.000193611987381703 0.000194400630914827 0.000194400630914827 0.000195386435331230 0.000196175078864353 0.000197160883280757 0.000202089905362776 0.000202089905362776 0.000202484227129338 0.000203667192429022 0.000203864353312303 0.000204258675078864 0.000204455835962145 0.000205441640378549 0.000205638801261830 0.000205835962145110 0.000206033123028391 0.000206230283911672 0.000206230283911672 0.000206230283911672 0.000206427444794953 0.000206427444794953 0.000205835962145110 0.000206033123028391 0.000207216088328076 0.000207413249211356 0.000207413249211356 0.000207413249211356 0.000207610410094637 0.000207610410094637 0.000207807570977918 0.000207610410094637 0.000207413249211356 0.000208004731861199 0.000208004731861199 0.000208201892744480 0.000208201892744480 0.000208399053627760 0.000208399053627760 0.000208399053627760 0.000208399053627760 0.000208399053627760 0.000208399053627760 0.000208399053627760 0.000208399053627760 0.000208596214511041 0.000208596214511041 0.000208793375394322 0.000208793375394322 0.000208793375394322 0.000208793375394322 0.000208793375394322 0.000208793375394322 0.000208990536277603 0.000208990536277603 0.000208990536277603 0.000208990536277603 0.000208990536277603 0.000208990536277603 0.000208990536277603 0.000208990536277603 0.000208990536277603 0.000209187697160883 0.000209187697160883 0.000209187697160883 0.000209187697160883 0.000209384858044164 0.000209582018927445 0.000209582018927445 0.000209779179810726 0.000209779179810726 0.000209779179810726 0.000209779179810726 0.000209779179810726 0.000209779179810726 0.000209779179810726 0.000209976340694006 0.000210173501577287 0.000210370662460568 0.000210370662460568 0.000210567823343849 0.000210764984227129 0.000210764984227129 0.000210764984227129 0.000210764984227129 0.000210764984227129 0.000210764984227129
0 Kommentare
Akzeptierte Antwort
Alan Stevens
am 28 Jul. 2020
Bearbeitet: Alan Stevens
am 28 Jul. 2020
The following works, but you get a lousy fit because of the huge range (orders of magnitude) between s and i and r. The error differences in i and r make a negigible contribution to the fit.
s = [0.999999802839117 0.999999408517350 0.999999605678233 0.999999408517350 0.999999605678233 0.999999605678233 0.999999408517350 0.999999408517350 0.999999211356467 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999999014195584 0.999998817034700 0.999998817034700 0.999998817034700 0.999998817034700 0.999998817034700 0.999998817034700 0.999998817034700 0.999998817034700 0.999998028391167 0.999998028391167 0.999998028391167 0.999997634069401 0.999997634069401 0.999995859621451 0.999995859621451 0.999995859621451 0.999995465299685 0.999995465299685 0.999994873817035 0.999994479495268 0.999994479495268 0.999991522082019 0.999989353312303 0.999986395899054 0.999985015772871 0.999983044164038 0.999979889589905 0.999970031545741 0.999962145110410 0.999954850157729 0.999947358044164 0.999935528391167 0.999920149842271 0.999911080441640 0.999901025236593 0.999888801261830 0.999875000000000 0.999868690851735 0.999862184542587 0.999851537854890 0.999844045741325 0.999833004731861 0.999825512618297 0.999820189274448 0.999818809148265 0.999783517350158 0.999780954258675 0.999779179810726 0.999743296529968 0.999735607255521 0.999733635646688 0.999731861198738 0.999731072555205 0.999715102523659 0.999714905362776 0.999714511041010 0.999713328075710 0.999653194006309 0.999652405362776 0.999652405362776 0.999651419558360 0.999651419558360 0.999651025236593 0.999651025236593 0.999638209779180 0.999613170347003 0.999612578864353 0.999610804416404 0.999609227129338 0.999608241324921 0.999604692429022 0.999602326498423 0.999600946372240 0.999599960567823 0.999598974763407 0.999597791798107 0.999596805993691 0.999591876971609 0.999591876971609 0.999591482649842 0.999589116719243 0.999588722397476 0.999588525236593 0.999587736593060 0.999586553627760 0.999586356466877 0.999585764984227 0.999585567823344 0.999585173501577 0.999585173501577 0.999585173501577 0.999584582018927 0.999584384858044 0.999585962145110 0.999585567823344 0.999584187697161 0.999583990536278 0.999583990536278 0.999583990536278 0.999583793375394 0.999583793375394 0.999583399053628 0.999583596214511 0.999583596214511 0.999583004731861 0.999582807570978 0.999582610410095 0.999582413249211 0.999582216088328 0.999582216088328 0.999582018927445 0.999581821766562 0.999581624605678 0.999581624605678 0.999581624605678 0.999581624605678 0.999581230283912 0.999581230283912 0.999581033123028 0.999581033123028 0.999581033123028 0.999581033123028 0.999581033123028 0.999581033123028 0.999580835962145 0.999580638801262 0.999580638801262 0.999580638801262 0.999580638801262 0.999580638801262 0.999580638801262 0.999580638801262 0.999580638801262 0.999580441640379 0.999580441640379 0.999580441640379 0.999580244479495 0.999580047318612 0.999579850157729 0.999579850157729 0.999579258675079 0.999579258675079 0.999579061514196 0.999579061514196 0.999579061514196 0.999579061514196 0.999579061514196 0.999578864353312 0.999578667192429 0.999578272870663 0.999578272870663 0.999577878548896 0.999577484227129 0.999577089905363 0.999577089905363 0.999577089905363 0.999577089905363 0.999577089905363];
i = [1.97160883280757e-07 5.91482649842271e-07 3.94321766561514e-07 5.91482649842271e-07 3.94321766561514e-07 3.94321766561514e-07 5.91482649842271e-07 5.91482649842271e-07 7.88643533123028e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 7.88643533123028e-07 7.88643533123028e-07 7.88643533123028e-07 7.88643533123028e-07 7.88643533123028e-07 7.88643533123028e-07 7.88643533123028e-07 7.88643533123028e-07 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.97160883280757e-06 1.97160883280757e-06 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 1.38012618296530e-06 1.38012618296530e-06 1.97160883280757e-06 2.36593059936909e-06 2.36593059936909e-06 5.32334384858044e-06 7.49211356466877e-06 1.04495268138801e-05 1.18296529968454e-05 1.38012618296530e-05 1.69558359621451e-05 2.68138801261830e-05 3.47003154574132e-05 4.19952681388013e-05 4.94873817034700e-05 6.13170347003155e-05 7.66955835962145e-05 8.57649842271293e-05 9.54258675078864e-05 0.000107649842271293 0.000121451104100946 0.000127365930599369 0.000133872239747634 0.000144518927444795 0.000152011041009464 0.000162263406940063 0.000169755520504732 0.000175078864353312 0.000176458990536278 0.000146687697160883 0.000149250788643533 0.000151025236593060 0.000119085173501577 0.000116127760252366 0.000117705047318612 0.000119479495268139 0.000120268138801262 0.000108635646687697 0.000108832807570978 0.000109227129337539 0.000110410094637224 5.34305993690852e-05 5.42192429022082e-05 5.42192429022082e-05 5.52050473186120e-05 5.52050473186120e-05 5.55993690851735e-05 5.55993690851735e-05 4.27839116719243e-05 1.93217665615142e-05 1.99132492113565e-05 1.85331230283912e-05 1.65615141955836e-05 1.55757097791798e-05 1.24211356466877e-05 1.04495268138801e-05 1.02523659305994e-05 1.12381703470032e-05 1.02523659305994e-05 9.85804416403786e-06 8.87223974763407e-06 3.94321766561514e-06 3.94321766561514e-06 3.54889589905363e-06 3.54889589905363e-06 3.54889589905363e-06 2.95741324921136e-06 3.35173501577287e-06 2.56309148264984e-06 2.36593059936909e-06 2.56309148264984e-06 2.36593059936909e-06 2.36593059936909e-06 2.36593059936909e-06 2.36593059936909e-06 2.56309148264984e-06 2.76025236593060e-06 2.36593059936909e-06 2.36593059936909e-06 1.38012618296530e-06 1.18296529968454e-06 1.18296529968454e-06 1.18296529968454e-06 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 1.18296529968454e-06 1.57728706624606e-06 9.85804416403786e-07 1.18296529968454e-06 9.85804416403786e-07 1.18296529968454e-06 9.85804416403786e-07 9.85804416403786e-07 1.18296529968454e-06 1.38012618296530e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.18296529968454e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.18296529968454e-06 1.18296529968454e-06 1.18296529968454e-06 1.38012618296530e-06 1.18296529968454e-06 9.85804416403786e-07 9.85804416403786e-07 1.18296529968454e-06 1.18296529968454e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.18296529968454e-06 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 9.85804416403786e-07 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06 1.38012618296530e-06];
r = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.97160883280757e-07 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.57728706624606e-06 1.77444794952681e-06 1.77444794952681e-06 1.77444794952681e-06 1.97160883280757e-06 1.97160883280757e-06 1.97160883280757e-06 1.97160883280757e-06 2.36593059936909e-06 2.36593059936909e-06 2.36593059936909e-06 2.36593059936909e-06 3.48974763406940e-05 3.48974763406940e-05 3.48974763406940e-05 6.88091482649842e-05 7.41324921135647e-05 7.43296529968454e-05 7.43296529968454e-05 7.43296529968454e-05 8.81309148264984e-05 8.81309148264984e-05 8.81309148264984e-05 8.81309148264984e-05 0.000146687697160883 0.000146687697160883 0.000146687697160883 0.000146687697160883 0.000146687697160883 0.000146687697160883 0.000146687697160883 0.000159503154574132 0.000183753943217666 0.000183753943217666 0.000185331230283912 0.000187105678233438 0.000188091482649842 0.000191443217665615 0.000193611987381703 0.000194400630914827 0.000194400630914827 0.000195386435331230 0.000196175078864353 0.000197160883280757 0.000202089905362776 0.000202089905362776 0.000202484227129338 0.000203667192429022 0.000203864353312303 0.000204258675078864 0.000204455835962145 0.000205441640378549 0.000205638801261830 0.000205835962145110 0.000206033123028391 0.000206230283911672 0.000206230283911672 0.000206230283911672 0.000206427444794953 0.000206427444794953 0.000205835962145110 0.000206033123028391 0.000207216088328076 0.000207413249211356 0.000207413249211356 0.000207413249211356 0.000207610410094637 0.000207610410094637 0.000207807570977918 0.000207610410094637 0.000207413249211356 0.000208004731861199 0.000208004731861199 0.000208201892744480 0.000208201892744480 0.000208399053627760 0.000208399053627760 0.000208399053627760 0.000208399053627760 0.000208399053627760 0.000208399053627760 0.000208399053627760 0.000208399053627760 0.000208596214511041 0.000208596214511041 0.000208793375394322 0.000208793375394322 0.000208793375394322 0.000208793375394322 0.000208793375394322 0.000208793375394322 0.000208990536277603 0.000208990536277603 0.000208990536277603 0.000208990536277603 0.000208990536277603 0.000208990536277603 0.000208990536277603 0.000208990536277603 0.000208990536277603 0.000209187697160883 0.000209187697160883 0.000209187697160883 0.000209187697160883 0.000209384858044164 0.000209582018927445 0.000209582018927445 0.000209779179810726 0.000209779179810726 0.000209779179810726 0.000209779179810726 0.000209779179810726 0.000209779179810726 0.000209779179810726 0.000209976340694006 0.000210173501577287 0.000210370662460568 0.000210370662460568 0.000210567823343849 0.000210764984227129 0.000210764984227129 0.000210764984227129 0.000210764984227129 0.000210764984227129 0.000210764984227129];
exp_y = [s(:); i(:); r(:)];
exp_t = 1:length(i);
p0 = [0.341 0.141]; %initial guess for beta and gamma, based on real world data
p_estimate = fminsearch(@(p)odefit(exp_t,exp_y,p),p0);
[~,Y] = ode45(@(t,y)odefun(t,y,p_estimate),exp_t,[1 1/5072000 0]);
S = Y(:,1); I = Y(:,2); R = Y(:,3);
plot(exp_t,i,'o',exp_t,r,'*',exp_t,I,exp_t,R)
legend('i','r','I','R')
figure
plot(exp_t,s,'o',exp_t,S)
legend('S')
function err = odefit(exp_t,exp_y,p)
[~,y] = ode45(@(t,y)odefun(t,y,p),exp_t,[1 1/5072000 0]); %initial conditions w/ 1 infected (i)
err = sum((y(:) - exp_y).^2); % This gives a lousy fit!
end
function dydt = odefun(~,y,p)
s = y(1);
i = y(2);
%r = y(3);
dydt = [-p(1) * s * i;
p(1) * s * i - p(2) * i;
p(2) * i];
end
6 Kommentare
Santanu Bhattacharya
am 1 Jun. 2022
Hi Alan, I have a similar issue regarding parameter estimation of Covid 19 SIRV model. Can you help me please...
Alan Stevens
am 1 Jun. 2022
You will need to upload the code you've used so far and explain your problem.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!