Error using vertcat Dimensions of arrays being concatenated are not consistent.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/988865/image.png)
0 Kommentare
Antworten (1)
KSSV
am 6 Mai 2022
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!