Error in ode45 (line 115) and odearguments (line 90)

1 回表示 (過去 30 日間)
jhdueon
jhdueon 2021 年 10 月 19 日
コメント済み: Star Strider 2021 年 10 月 19 日
Hello all together,
I have written the following code, but it keeping getting the same error:
function dydt=overwork(t,y,re,rr,oe,or,be,br,ae,ar)
dydt=zeros(2,1);
dydt(1)=y(1)*(1-y(1))*(y(2)*(oe*re-be*rr)-ae*re);
dydt(2)=y(2)*(1-y(2))*((y(1)*(or*rr-br*re)-ar*rr);
end
clc;
clear;
re=5;
rr=5;
oe=0.7;
or=0.7;
be=0.2;
br=0.2;
ae=0.4;
ar=0.2;
figure(1)
[t,y]=ode45(@(t,y) overwork(t,y,re,rr,oe,or,be,br,ae,ar),[0,20],[0.1,0.5]);
plot(y(:,1),y(:,2),'rh-','linewidth',1,'markersize',5,'markerfacecolor','r','markerindices');
grid on
hold on
xlabel('$x$','interpreter','latex','Rotation',0);
ylabel('$y$','interpreter','latex','Rotation',360);
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);
Error in overwork2 (line 12)
[t,y]=ode45(@(t,y) overwork(t,y,re,rr,oe,or,be,br,ae,ar),[0,20],[0.1,0.5]);
Can somebody help me?
Thanks in advance and best regards to you all.

採用された回答

Star Strider
Star Strider 2021 年 10 月 19 日
There were two errors.
First:
dydt(2)=y(2)*(1-y(2))*((y(1)*(or*rr-br*re)-ar*rr);
↑ ← EXTRA UNMATCHED PARENTHESIS
Second:
In the plot call, 'markerindices' has a name although no associated values, throwing an error. (I deleted it.)
re=5;
rr=5;
oe=0.7;
or=0.7;
be=0.2;
br=0.2;
ae=0.4;
ar=0.2;
figure(1)
[t,y]=ode45(@(t,y) overwork(t,y,re,rr,oe,or,be,br,ae,ar),[0,20],[0.1,0.5]);
plot(y(:,1),y(:,2),'r-','linewidth',1,'markersize',5,'markerfacecolor','r');
grid on
hold on
xlabel('$x$','interpreter','latex','Rotation',0);
ylabel('$y$','interpreter','latex','Rotation',360);
function dydt=overwork(t,y,re,rr,oe,or,be,br,ae,ar)
dydt=zeros(2,1);
dydt(1)=y(1)*(1-y(1))*(y(2)*(oe*re-be*rr)-ae*re);
dydt(2)=y(2)*(1-y(2))*(y(1)*(or*rr-br*re)-ar*rr);
end
With those corrections, it works!
.
  2 件のコメント
jhdueon
jhdueon 2021 年 10 月 19 日
the "EXTRA UNMATCHED PARENTHESIS" really matters!! Thanks!!
Star Strider
Star Strider 2021 年 10 月 19 日
As always, my pleasure!
.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHistorical Contests についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by