Illegal use of reserved keyword "end"
7 views (last 30 days)
Show older comments
I am running this MATLAB code but it is giving me illegal use of keyword end, I checked the whole code and it has all brackets closed also, here is code:
%SEIQR model (equilibrium solution with time delay)
S = 2.376543 ;% Initial number of susceptible people in million
E = 2.557000 ;%Number of exposed people in million
I = 0; % Initial number of infected people
Q = 0 ;% Initial quarantined number
R = 0 ;% Initial number of recovered people
r1 = 2.5 ;% average susceptible contact number
r2 = 0.5 ;% average quarantine contact number
alpha=0.922; % infection rate in exposed people
r=0.303; % rate of infection
d1=0; % average natural death rate
d2=0.001; % average covid induced death rate
beta1=0.80; %infection rate per infected person
beta2=0.0701; % infection rate per quarantined person
gamma1= 0.01;% recovery rate in exposed people
gamma2= 0.01;% recovery rate in infected people
gamma3= 0.05;% recovery rate in quarantined people
M=1;
h = 0.01 ;% differential time interval
T = h:h:500 ;
foridx = 1:length(T)-1;
S(idx+1) = S(idx) + h*(M-alpha*S(idx)*E(idx) - d1*S(idx)) ;
E(idx+1) = E(idx) + h*(-alpha*S(idx)*E(idx) - d1*E(idx) - r*E(idx)) ;
I(idx+1) = I(idx) + h*(r*E(idx) -d2*I(idx)-d1*I(idx)-gamma2*I(idx)-beta2*I(idx)) ;
Q(idx+1) = Q(idx) + h*(beta1*E(idx) + beta2*I(idx)-d1*Q(idx)-d2*Q(idx)-gamma1*Q(idx)) ;
R(idx+1) = R(idx) + h*(gamma1*Q(idx)+gamma2*I(idx)+gamma3*E(idx)-d1*R(idx)) ;
end
clear; clc;
beta = 1.9; % contact rate per day
a1 = 0.3; % quarantine rate in exposed people
a2 = 0.2; % quarantine rate in infected people
r=0.303;
gamma1= 0.02;% recovery rate in exposed people
gamma2= 0.02;% recovery rate in infected people
gamma3= 0.09;% recovery rate in quarantined people
mu= 0.06; % natural death rate
beta1=0.8;
beta2=0.0701;
tau =14; %time delay (incubation period)
M=1;
d1 = 0.04;% death rate in infected people
d2 = 0.02;% death rate in quarantined people
ddeSEIQR = @(t,y,Z) [M-beta*y(1)*y(3)-d1*y(1) ;
(beta*y(1)*y(3))-d1*exp(-mu*tau)*Z(2,1)-r*y(2)-gamma3*y(2)-beta1*y(2) ; %Z(2,1) approximates the delay in exposed population
beta*exp(-mu*tau)*Z(2,1)-d2*y(3)-d1*y(3)-gamma2*y(3)-beta2*y(3) ;
beta1*y(2)+beta2*y(3)-d1*y(4)-d2*y(4)-gamma1*y(4) ;
gamma1*y(4)+gamma2*y(3)+gamma3*y(2)-d1*y(5)] ;
sol = dde23(ddeSEIQR,[14,1], [0.99 0 0.01 0 0] , [0 , 100]) ;%dde23 (@. . . . , tau , history ,tspan ;
figure ;
plot(sol.x,sol.y(1,:), 'r', LineWidth=2)
holdon
plot(sol.x,sol.y(2,:),'g', LineWidth=2)
holdon
plot(sol.x,sol.y(3,:),Linewidth=2)
holdon
plot(sol.x ,sol.y(4,:),Linewidth=2)
holdon
plot(sol.x,sol.y(5,:),Linewidth=2)
holdoff
title('SEIQR at equilibrium');
xlabel ('time(days)') ;
ylabel ('steady state solution') ;
legend ('S','E','I','Q','R') ;
3 Comments
John D'Errico
on 11 Jan 2025
Thereby creating a (never used) variable named foridx.
Funny how your mind skips over the missing space too easily. You know what the line is supposed to do. And so you don't see the lack of a space. I've seen that class of mistake arise often enough.
Walter Roberson
on 11 Jan 2025
holdon
holdoff
The correct form of those commands is
hold on
hold off
Answers (1)
VBBV
on 11 Jan 2025
for idx = 1:length(T)-1; %
Give a space in for loop statement to close the loop
2 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!