Plot Population growth function with different values of b using for loop
Afficher commentaires plus anciens
I need to plot population growth model with different values of b
where b>d
and b=d
using for loops. Both results should be visible on the same graph with different colors.
Here is my function and intial value, but I am not getting how to get the plot .
H=@(t,N)[b*N-d*N];
[T,Y]=ode45(H,[0:1:time],[N0]);
Intitial value
b= 0.1 0.001
d=0.001
N0=400
I need two line for each b on the same plot.
Réponses (1)
f = @(t,b,d,N0) N0*exp((b-d)*t);
t = 0:0.1:10;
N0 = 400;
b = [0.1 0.001].';
d = 0.001;
plot(t,f(t,b,d,N0))
grid on
10 commentaires
b = [0.1 0.001];
d = 0.001;
N0 = 400;
time = 400;
hold on
for i = 1:numel(b)
H=@(t,N)[b(i)*N-d*N];
[T,Y] = ode45(H,[0:1:time],[N0]);
plot(T,Y)
end
hold off
grid on
Saira
le 2 Fév 2023
Saira
le 2 Fév 2023
Saira
le 2 Fév 2023
Torsten
le 2 Fév 2023
I don't understand your point.
The parameters are different for the two cases - so the results are different.
Saira
le 2 Fév 2023
Torsten
le 2 Fév 2023
Maybe 400 looks like 0 in the loop plot because the second plot gives such large results for N.
Look at the plot from my code above. The red line looks like 0 because the blue line gets up to about 7e19, but is 400.
Saira
le 2 Fév 2023
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

