Here are the command i have input:
syms S I R beta gamma B mi
eqns = [B-beta*S*I-gamma*I-mi*I==0, gamma*I-mi*R==0];
Sol=solve(eqns, [S I R]);
y0=[1000 20 0];
tspan=[0 100];
beta = 0.00004;
gamma = 0.009;
[t,y] = ode45(@(t,y) sir_eq(t,y,beta,gamma),tspan,y0);
I am met with:
Error in @(t,y)sir_eq(t,y,beta,gamma)
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Could anyone explain what exactly the error is/what i need to do? Thanks

 Respuesta aceptada

Star Strider
Star Strider el 29 de Abr. de 2020

0 votos

Your equations must be set up as differential equations, using the Symbolic Math Toolbox diff function to create the derivatives.
Then, use the odeToVectorField and matlabFunction functions to create the necessary first-degree equations and the anonymous function to use with ode45.

2 comentarios

Diren Nayir
Diren Nayir el 29 de Abr. de 2020
I set up the differential equations in a sir_eq.m script and it worked. Thank you!!!
Star Strider
Star Strider el 29 de Abr. de 2020
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Symbolic Math Toolbox en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 29 de Abr. de 2020

Comentada:

el 29 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by