Matrix dimensions must agree.
조회 수: 2 (최근 30일)
이전 댓글 표시
I have an error in the following code. Could anyone help me to correct it?
clear, clc;
aeta=0;
beta=0.75;
d=0;
eps=0.0006;
sigma=1/3;
Gam=1./8;
h=0.1;
alpha=[0.5; 0.6; 0.7; 1.0];
M=2/(2-alpha);
t=0:h:100;
n=length(t);
m=length(alpha);
solS=[]; solE=[]; solI=[]; solN=[];
for k=1:m
S=zeros(n, 1);
E=S; I=S; N=S;
E(1)=20000; I(1)=1; N(1)=10*10^6;
S(1)=N(1)-E(1)-1;
for i = 2 : n-1
S(i+1)=S(1)+((1-alpha)/M+(3*h)/(2*M))*(aeta-(beta*S(i)*I(i))/N(i)-d*S(i))-((1-alpha)/M+(alpha*h)/(2*M))*(aeta-(beta*S(i-1)*I(i-1))/N(i-1)-d*S(i-1));
E(i+1)=E(i)+(h^alpha(k)/gamma(alpha(k)+1))*((beta*S(i)*I(i))/N(i)-(sigma+d)*E(i));
I(i+1)=I(i)+(h^alpha(k)/gamma(alpha(k)+1))*(sigma*E(i)-(Gam+d+eps)*I(i));
N(i+1)=N(i)+(h^alpha(k)/gamma(alpha(k)+1))*(aeta-d*N(i)+eps*I(i));
end
solS(:, k) = S(:); solE(:, k) = E(:); solI(:, k) = I(:); solN(:, k) = N(:);
end
plot (t,solI(:,1),'r', t, solI(:,2),'g', t, solI(:,3),'k', t, solI(:,4),'b');
xlabel ('Time'), ylabel('Infectious'), title('Size of the infectious versus time with no treatment for diferent values of order alpha');
legend ('alpha=0.5','alpha=0.6','alpha=0.7','alpha=1.0')
댓글 수: 2
KSSV
2020년 5월 8일
YOur alpha is array...you cnnot do like that....replacing / with ./ also will not work. May be you have to run a loop for alpha and do other caculations in vector.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!