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

조회 수: 1 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by