How to make this ode45 work?

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

 采纳的回答

Star Strider
Star Strider 2020-4-29

0 个投票

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 个评论

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

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by