How to solve a system of 4 ODEs?

5 visualizzazioni (ultimi 30 giorni)
Shravan Nair
Shravan Nair il 26 Set 2020
Commentato: Star Strider il 26 Set 2020
I'm new to MATLAB and I'm stuck on this problem for days now. I have a model of 4 different equations and I cant figure out how to solve it. Please help me.
betah = 1000; betam = 300;
gammah = 0.004; gammam = 0.06;
muh = 0.3; mum = 0.3;
alphah = 0.000353; alpham = 0.00012;
theta = 0.4;
These are the initial values of the constants, and the equations are given below.
dShdt = betah - alphah*Sh*Im - gammah*Sh + theta*Ih;
dIhdt = -muh*Ih + alphah*Sh*Im - gammah*Ih - theta*Ih;
dSmdt = betam - alpham*Sm*Ih - gammam*Sm;
dImdt = -mum*Im + alpham*Sm*Ih - gammam*Im;
  2 Commenti
Ameer Hamza
Ameer Hamza il 26 Set 2020
Can you attach the variables in mathematical notation? Also, which of these variables are the constant parameters, and which are state variables?
Shravan Nair
Shravan Nair il 26 Set 2020
The variables are Sh, Ih, Sm, Im. Rest are all constants.

Accedi per commentare.

Risposta accettata

Star Strider
Star Strider il 26 Set 2020
Try this:
syms Sh(t) Ih(t) Sm(t) Im(t) Sh0 Ih0 Sm0 Im0 T Y
betah = 1000; betam = 300;
gammah = 0.004; gammam = 0.06;
muh = 0.3; mum = 0.3;
alphah = 0.000353; alpham = 0.00012;
theta = 0.4;
DE1 = diff(Sh) == betah - alphah*Sh*Im - gammah*Sh + theta*Ih;
DE2 = diff(Ih) == -muh*Ih + alphah*Sh*Im - gammah*Ih - theta*Ih;
DE3 = diff(Sm) == betam - alpham*Sm*Ih - gammam*Sm;
DE4 = diff(Im) == -mum*Im + alpham*Sm*Ih - gammam*Im;
[VF,Sbs] = odeToVectorField(DE1,DE2,DE3,DE4);
ODEfcn = matlabFunction(VF, 'Vars',{T,Y})
tspan = [0,50]; % Choose An Appropriate Time Span Or Vector
ic = zeros(4,1)+0.1; % Appropriate ?Initial Conditions
[t,y] = ode45(ODEfcn, tspan, ic);
figure
plot(t, y)
grid
legend(string(Sbs))
producing:
ODEfcn = @(T,Y)[Y(1).*(-8.8e+1./1.25e+2)+Y(2).*Y(4).*3.53e-4;Y(1).*(2.0./5.0)-Y(2)./2.5e+2-Y(2).*Y(4).*3.53e-4+1.0e+3;Y(3).*(-3.0./5.0e+1)-Y(1).*Y(3).*1.2e-4+3.0e+2;Y(4).*(-9.0./2.5e+1)+Y(1).*Y(3).*1.2e-4];
and a plot.
  5 Commenti
Star Strider
Star Strider il 26 Set 2020
This call to odeToVectorField:
[VF,Sbs] = odeToVectorField(DE1,DE2,DE3,DE4);
creates the system of diffferential equations as a vector of first-order differential equations, required for the numeric solvers. It also returns the ‘Sbs’ output shows the substitutions conde to create ‘VF’, so ‘Sbs(1)’ defines ‘VF(1)’ and so for the others.
This call to matlabFunction:
ODEfcn = matlabFunction(VF, 'Vars',{T,Y})
converts the vector field vector ‘VF’ to an anonymous function (here) that the numeric ODE solvers can use.
The rest of the code calls ode45 to integrate the ‘ODEfcn’ system, then plots it. The string function neatly takes the ‘Sbs’ vector and converts it to a string vector that legend can use to describe the plotted curves.
Star Strider
Star Strider il 26 Set 2020
If my Answer helped you solve your problem, please Accept it!
.

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by