How to add number from equation to array and display it on chart
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
VBBV
on 12 Mar 2023
Edited: VBBV
on 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')
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!