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

1 visualización (últimos 30 días)
jhdueon
jhdueon el 19 de Oct. de 2021
Comentada: Star Strider el 19 de Oct. de 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.

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Historical Contests en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by