Clear Filters
Clear Filters

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 view (last 30 days)
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))

Answers (2)

Arif Hoq
Arif Hoq on 14 Mar 2022
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 on 14 Mar 2022
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

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!