How to add number from equation to array and display it on chart

7 ビュー (過去 30 日間)
Gabriela Ziola
Gabriela Ziola 2023 年 3 月 12 日
コメント済み: Gabriela Ziola 2023 年 3 月 12 日
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

採用された回答

VBBV
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 ExchangePerformance and Memory についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by