Error using vertcat Dimensions of arrays being concatenated are not consistent.

조회 수: 2 (최근 30일)
Kesavan K
Kesavan K 2022년 5월 6일
답변: KSSV 2022년 5월 6일
I have tried to code Covid19 mathematical model but got "Error using vertcat" everytime.
This is a SEIRD model.
function [time,state_values]= mathematical
%%Initial values
t0 = 0;
tend = 100;
tspan=[t0,tend];
y0 = [100,10,3,0,0];
%%Constant(rates) values
A=0;
e=0.3;
a=0.4;
g=0.23;
k=0.3;
p=0.25;
m=0.12;
b=0.45;
s=y0;
%% [sdot] = g(t,s)
sdot = [A-(e*s(1)*s(2))-(a*s(1)*s(3))+(g*s(4));
-((k+p)*s(2)) +(e*s(1)*s(2))+(a*s(1)*s(3));
-((b+m)*s(3)) +(k*s(2));
-(g*s(4))+ (p*s(2))+(b*s(3));
(m*s(3))];
%%Calling ODE45 solver
[time, state_values] = ode45(@(t,s) sdot,tspan,y0);
%%Extracting individual values
S= state_values(:,1);
E= state_values(:,2);
I= state_values(:,3);
R= state_values(:,4);
D= state_values(:,5);
%%Plot S,E,I,R,D
figure(1)
clf
plot(time,S); title('Susceptible Population vs Time')
figure(2)
clf
plot(time,E); title('Exposed Population vs Time')
figure(3)
clf
plot(time,I); title('Infected Population vs Time')
figure(4)
clf
plot(time,R); title('Recovered Population vs Time')
figure(5)
clf
plot(time,D); title('Death Population vs Time')
end

답변 (1개)

KSSV
KSSV 2022년 5월 6일
Becareful while leaving space between terms in the array.
function [time,state_values]= mathematical
%%Initial values
t0 = 0;
tend = 100;
tspan=[t0,tend];
y0 = [100,10,3,0,0];
%%Constant(rates) values
A=0;
e=0.3;
a=0.4;
g=0.23;
k=0.3;
p=0.25;
m=0.12;
b=0.45;
s=y0;
%% [sdot] = g(t,s)
sdot = [A-(e*s(1)*s(2))-(a*s(1)*s(3))+(g*s(4));
-((k+p)*s(2))+(e*s(1)*s(2))+(a*s(1)*s(3));......
-((b+m)*s(3))+(k*s(2));
-(g*s(4))+(p*s(2))+(b*s(3));
(m*s(3))];
%%Calling ODE45 solver
[time, state_values] = ode45(@(t,s) sdot,tspan,y0);
%%Extracting individual values
S= state_values(:,1);
E= state_values(:,2);
I= state_values(:,3);
R= state_values(:,4);
D= state_values(:,5);
%%Plot S,E,I,R,D
figure(1)
clf
plot(time,S); title('Susceptible Population vs Time')
figure(2)
clf
plot(time,E); title('Exposed Population vs Time')
figure(3)
clf
plot(time,I); title('Infected Population vs Time')
figure(4)
clf
plot(time,R); title('Recovered Population vs Time')
figure(5)
clf
plot(time,D); title('Death Population vs Time')
end

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by