ODE modeling in 3- dimension and looping
Ältere Kommentare anzeigen
I simulating an ODE using function ode15s. I set up the output as:
Classes = struct('S', zeros(length(tspan), n, soc), 'E', zeros(length(tspan), n, soc), ...
'A', zeros(length(tspan), n, soc), 'J', zeros(length(tspan), n, soc), ...
'Q', zeros(length(tspan), n, soc), 'I', zeros(length(tspan), n, soc), ...
'H', zeros(length(tspan), n, soc), 'R', zeros(length(tspan), n, soc), ...
'D', zeros(length(tspan), n, soc), 'Ir', zeros(length(tspan), n, soc), 't', []);
The initail condition is a 10 by 21 matrix with I looped over to have a 1 by 21, so that I can simulate for each group n =10.
After I extracted the updated population as, which is inside a loop:
Classes.S(:, :, i) = pop(:, 1:n);
Classes.E(:, :, i) = pop(:, n+1:2*n);
Classes.A(:, :, i) = pop(:, 2*n+1:3*n);
Classes.J(:, :, i) = pop(:, 3*n+1:4*n);
Classes.Q(:, :, i) = pop(:, 4*n+1:5*n);
Classes.I(:, :, i) = pop(:, 5*n+1:6*n);
Classes.H(:, :, i) = pop(:, 6*n+1:7*n);
Classes.R(:, :, i) = pop(:, 7*n+1:8*n);
Classes.D(:, :, i) = pop(:, 8*n+1:9*n);
Classes.Ir(:, :,i) = pop(:, 9*n+1:10*n);
I now extract the solution at each time t
Sk = zeros(n,soc); Ek = zeros(n,soc); Ak = zeros(n,soc); Jk = zeros(n,soc);
Qk = zeros(n,soc); Ik = zeros(n,soc); Hk = zeros(n,soc); Rk = zeros(n,soc);
Dk = zeros(n,soc); Irk = zeros(n,soc);
for j =1:soc
S(:,:,j) = reshape(pop(1:1:n), n, 1);
Sk(:,j) = S(:,:,j);
E(:,:,j) = reshape(pop(n+1:1:2*n), n, 1);
Ek(:,j) = E(:,:,j);
A(:,:,j) = reshape(pop((2*n)+1:1:3*n), n, 1);
Ak(:,j) = A(:,:,j);
J(:,:,j) = reshape(pop((3*n)+1:1:4*n), n, 1);
Jk(:,j) = J(:,:,j);
Q(:,:,j) = reshape(pop((4*n)+1:1:5*n), n, 1);
Qk(:,j) = Q(:,:,j);
I(:,:,j) = reshape(pop((5*n)+1:1:6*n), n, 1);
Ik(:,j) = I(:,:,j);
H(:,:,j) = reshape(pop((6*n)+1:1:7*n), n, 1);
Hk(:,j) = H(:,:,j);
R(:,:,j) = reshape(pop((7*n)+1:1:8*n), n, 1);
Rk(:,j) = R(:,:,j);
D(:,:,j) = reshape(pop((8*n)+1:1:9*n), n, 1);
Dk(:,j) = D(:,:,j);
Ir(:,:,j) = reshape(pop((9*n)+1:1:10*n), n, 1);
Irk(:,j) = Ir(:,:,j);
end
What I want to do with Sk (10 by 21) is to be able to subset Sk, such that Sk(1 by 21) is the vector of group 1 by 21 and Sk(2 by 21) is group 2 by 21. however the code line seems to be repeating the same thing for 1 to 10.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Programming finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!