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

 Accepted Answer

Star Strider
Star Strider on 29 Apr 2020
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 Comments

I set up the differential equations in a sir_eq.m script and it worked. Thank you!!!
As always, my pleasure!

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!