Which is the most efficient way to solve a ODE that has a parameter that changes in every period?
Afficher commentaires plus anciens
The problem I have to solve is to choose optimally teh parameters of a system of differential equations. The problem is that one of the parameters depends on a function (which are the parameters I need to choose) and the value changes in every period. So, in order to choose the parameters I minimize the square error of the fitted model with some actual data. The problem is that the algorithm is really slow and I need to optimize it. In every step I need to redefine the ODE model in the following way:
syms S(t) I(t) R(t) D(t)
odeS = diff(S) == -beta*I*S/pop;
odeI = diff(I) == beta*I*S/pop - gamma*I-mu*I;
odeR = diff(R) == gamma*I;
odeD = diff(D) == mu*I;
% Transform the equations for the numerical solver
odes = [odeS; odeI; odeR; odeD];
odes2 = odeToVectorField(odes);
eq_mat = matlabFunction(odes2, 'Vars', {'t', 'Y'});
ic = [s0, i0, r0, d0];
tspan = [0, 100];
[t, y]= ode45(eq_mat, tspan, ic);
The problem is that in every period the value of beta changes and i need to run all the latter lines again and that takes time. I have tried other things but are even slower.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
