How to add number from equation to array and display it on chart
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
VBBV
2023-3-12
编辑:VBBV
2023-3-12
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')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!