How to add number from equation to array and display it on chart
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I just stared Matlab on my University but I have never been IT related person. I just got some mandatory tasks to do before first lessons.
We have to calculate the number of individuals in some group after some hours using this formula:
Nt = N0 * (exp(1) ^ (r * t))
r=log(2)/tD
Where N0 (number of individuals) is 100, tD (time of double reproduction) = 5 and t (hours) = 10. Nt is number after set time.
We have to show that on chart showing changes every hour.
After some hours of work and research I came to this:
clear all;
close all;
clc;
Time = [0];
Quantity = [0];
N0 = input('N0 = ');
tD = input('tD = ');
t = input('t = ');
r=log(2)/tD;
i=0,1,9;
for i=i
Nt = N0 * (exp(1) ^ (r * t));
Quantity = Nt;
Time = Time + 1;
end
figure ()
hold on
plot(Time,Quantity)
title('Chart')
xlabel('Time')
ylabel('Quantity')
But it doesn't work.. I'm getting error in that loop.
Can someone help me?
Thank you
0 commentaires
Réponse acceptée
VBBV
le 12 Mar 2023
Modifié(e) : VBBV
le 12 Mar 2023
clear all;
close all;
clc;
Time(1) = [0];
Quantity(1) = [0];
N0 = 100 ;
tD = 5;
t = 10;
r=log(2)/tD
for i=1:length(1:1:t)
Nt = N0 * (exp (r * i));
Quantity(i+1) = Nt;
Time(i+1) = Time(i) + 1;
end
figure ()
hold on
plot(Time,Quantity)
xticks(1:10)
title('Chart')
xlabel('Time')
ylabel('Quantity')
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!