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

1 Ansicht (letzte 30 Tage)
jhdueon
jhdueon am 19 Okt. 2021
Kommentiert: Star Strider am 19 Okt. 2021
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.

Akzeptierte Antwort

Star Strider
Star Strider am 19 Okt. 2021
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 Kommentare
jhdueon
jhdueon am 19 Okt. 2021
the "EXTRA UNMATCHED PARENTHESIS" really matters!! Thanks!!
Star Strider
Star Strider am 19 Okt. 2021
As always, my pleasure!
.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Historical Contests finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by