This is from the actual tutorial: https://www.youtube.com/watch?v=9nnaFaDlmuc&feature=youtu.be
but when I plug the following commands in :
tSpan=[0;10]; x0=[4999;1;0]; [tSol,xSol] =ode45(@SIRmodel,tSpan, x0) function dxdt=SIRmodel(t,x) dxdt=[-2*x(1)*x(2)/5000; 2*x(1)*x(2)/5000-2*x(2)/3;2*x(2)/3]; end
I get this error message: Undefined function or variable 'SIRmodel'.
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);
>> Was there a mistake in the video?

 채택된 답변

Star Strider
Star Strider 2018년 3월 18일

0 개 추천

The easy solution is to create ‘SIRmodel’ as an anonymous function.
This works:
SIRmodel = @(t,x) [-2*x(1)*x(2)/5000; 2*x(1)*x(2)/5000-2*x(2)/3;2*x(2)/3];
tSpan=[0;10];
x0=[4999;1;0];
[tSol,xSol] = ode45(SIRmodel,tSpan, x0);
figure(1)
plot(tSol, xSol)
grid
To use it as you did, you need to save it as its own separate ‘.m’ file as SIRmodel.m. (If you have R2017b or later, saving it at the end of a script file would probably work.) See the documentation on Function Basics (link) for details, as well as the documentation on Anonymous Functions (link).

댓글 수: 2

Saskya Byerly
Saskya Byerly 2018년 3월 18일
Thank you!
Star Strider
Star Strider 2018년 3월 18일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2018년 3월 18일

댓글:

2018년 3월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by