How do i write this code for different timestep like this code is for 3600 and i want to use different timesteps like 1800,900,450

1 次查看(过去 30 天)
nsteps = 12;
t = zeros (nsteps,1);
A = zeros (nsteps,1);
B = zeros(nsteps, 1);
P = zeros(nsteps,1);
A(1) = 1;
B(1) = 3;
C(1) = 0;
K = 5*10^-5
for k = 2:13
t(k) = t(k-1)+3600
A(k) = A(k-1)+(-K*A(k-1)*B(k-1))*3600;
B(k) = B(k-1)+(-Yb*(K*A(k-1)*B(k-1)))*3600;
P(k)= P(k-1)+ Yp*(K*A(k-1)*B(k-1))*3600;
end
plot (t,A)
figure (1)
plot(t,A(:,1))
plot (t,B)
figure (2)
plot(t,B(:,1))
plot(t,P)
figure (3)
plot(t,P(:,1))

回答(2 个)

Arif Hoq
Arif Hoq 2022-3-14
I have considered Yb=5 and Yp=8.
nsteps = 12;
t = zeros (nsteps,1);
A = zeros (nsteps,1);
B = zeros(nsteps, 1);
P = zeros(nsteps,1);
A(1) = 1;
B(1) = 3;
C(1) = 0;
Yb=5;
Yp=8;
K = 5*10^-5
timestep=[450 900 1800 3600];
for k = 2:13
for j=1:length(timestep)
t(k) = t(k-1)+timestep(j)
A(k) = A(k-1)+(-K*A(k-1)*B(k-1))*timestep(j);
B(k) = B(k-1)+(-Yb*(K*A(k-1)*B(k-1)))*timestep(j);
P(k)= P(k-1)+ Yp*(K*A(k-1)*B(k-1))*timestep(j);
end
end
plot (t,A)
figure (1)
plot(t,A(:,1))
plot (t,B)
figure (2)
plot(t,B(:,1))
plot(t,P)
figure (3)
plot(t,P(:,1))

KSSV
KSSV 2022-3-14
dt = [3600 1800 900 450] ;
for i = 1:length(dt)
nsteps = 12;
t = zeros (nsteps,1);
A = zeros (nsteps,1);
B = zeros(nsteps, 1);
P = zeros(nsteps,1);
A(1) = 1;
B(1) = 3;
C(1) = 0;
K = 5*10^-5
for k = 2:13
t(k) = t(k-1)+dt(i)
A(k) = A(k-1)+(-K*A(k-1)*B(k-1))*dt(i);
B(k) = B(k-1)+(-Yb*(K*A(k-1)*B(k-1)))*dt(i);
P(k)= P(k-1)+ Yp*(K*A(k-1)*B(k-1))*dt(i);
end
plot (t,A)
figure (1)
plot(t,A(:,1))
plot (t,B)
figure (2)
plot(t,B(:,1))
plot(t,P)
figure (3)
plot(t,P(:,1))
end

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by