MATLAB: How to make this ode45 work

ode45

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

Best Answer

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.