Error: In an assignment A(I) = B, the number of elements in B and I must be the same.
1 view (last 30 days)
Show older comments
Hello everyone. Here is the code that gives me the following error:
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in SeasonalityLVEbif>Preypred (line 33)
Ydot(1) =(alpha1*(Ke-Y(1)))+Ke*pi*Y(2)/6;
The code :
function SeasonalityLVEbif
rect=[200 80 700 650];%fix the window size and position
set(0,'defaultfigureposition',rect);
global alpha1 b P theta q c a e d
alpha1=0.5; b=1.2; P=0.025; theta= 0.03;q=0.0038; c= 0.81; a= 0.25; e=0.8; d=0.25;
option=odeset('AbsTol',1e-11,'RelTol',1e-11);
inc=[0.01:1:220]';
time=[ inc ] ;
limit=[200:1:220];
ymin=[];
ymax=[];
for Ke=0.01:0.05:2,
IC=[1.5 1 0 0.5 0.25 ];
[t,U]=ode45(@Preypred,time,IC);
u1=U(limit,1);
ymin=[ymin,min(u1)];
ymax=[ymax,max(u1)];
end
X=0.01:0.05:2;
figure
plot(X, ymin,'g.',X, ymax,'k.');
legend('grazer min','grazer max'),
hold on
xlim([0.01 2]);
title('Bifurcation diagram for LVE model','FontSize',12)
xlabel('Ke, the equilibrium carrying capacity');
ylabel('grazer','Rotation',90);
function [Ydot] = Preypred(t,Y)
global alpha1 Ke b P theta q c a e d
Ydot(1) =(alpha1*(Ke-Y(1)))+Ke*pi*Y(2)/6;
Ydot(2) =Y(2)*(1-Y(2)^2-Y(3)^2)-2*pi*Y(3)/6;
Ydot(3) = Y(3)*(1-Y(2)^2-Y(3)^2)+2*pi*Y(2)/6;
Ydot(4) = b*Y(4)*(1-Y(4)/(min(Y(1),(P-theta*Y(5))/q)))-c*Y(4)*Y(5)/(a+Y(4));
Ydot(5) = e*min(1,((P-theta*Y(5))/Y(4))/theta)*c*Y(4)*Y(5)/(a+Y(4))-d*Y(5);
Ydot=Ydot';
Could you please help me to fix it?
1 Comment
Accepted Answer
KSSV
on 16 Oct 2017
function SeasonalityLVEbif
rect=[200 80 700 650];%fix the window size and position
set(0,'defaultfigureposition',rect);
% global alpha1 b P theta q c a e d
values = struct ;
values.alpha1=0.5;
values.b=1.2;
values.P=0.025;
values.theta= 0.03;
values.q=0.0038;
values.c= 0.81;
values.a= 0.25;
values.e=0.8;
values.d=0.25;
option=odeset('AbsTol',1e-11,'RelTol',1e-11);
inc=[0.01:1:220]';
time=[ inc ] ;
limit=[200:1:220];
ymin=[];
ymax=[];
for Ke=0.01:0.05:2
IC=[1.5 1 0 0.5 0.25 ];
[t,U]=ode45(@Preypred,time,IC,[],values,Ke);
u1=U(limit,1);
ymin=[ymin,min(u1)];
ymax=[ymax,max(u1)];
end
X=0.01:0.05:2;
figure
plot(X, ymin,'g.',X, ymax,'k.');
legend('grazer min','grazer max'),
hold on
xlim([0.01 2]);
title('Bifurcation diagram for LVE model','FontSize',12)
xlabel('Ke, the equilibrium carrying capacity');
ylabel('grazer','Rotation',90);
function [Ydot] = Preypred(t,Y,values,Ke)
Ydot = zeros(1,5) ;
alpha1 = values.alpha1 ;
b = values.b ;
P = values.P ;
theta = values.theta ;
q = values.q ;
c = values.c ;
a = values.a ;
e = values.e ;
d = values.d ;
Ydot(1) =(alpha1*(Ke-Y(1)))+Ke*pi*Y(2)/6;
Ydot(2) =Y(2)*(1-Y(2)^2-Y(3)^2)-2*pi*Y(3)/6;
Ydot(3) = Y(3)*(1-Y(2)^2-Y(3)^2)+2*pi*Y(2)/6;
Ydot(4) = b*Y(4)*(1-Y(4)/(min(Y(1),(P-theta*Y(5))/q)))-c*Y(4)*Y(5)/(a+Y(4));
Ydot(5) = e*min(1,((P-theta*Y(5))/Y(4))/theta)*c*Y(4)*Y(5)/(a+Y(4))-d*Y(5);
Ydot=Ydot';
More Answers (0)
See Also
Categories
Find more on Argument Definitions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!