How do I plot a function with a variable that has multiple values?

I am new to Matlab and I am trying to plot the following function where T0 needs to have multiple values:
k=1;
T0=20;
Tm=25;
t=linspace(0,30,100);
T=Tm+(T0-Tm)*exp(-k*t);
plot(t,T)
axis([0 30 0 60])
I have been trying to assign multiple values for T0 but I get an error every time. Can anyone help?

답변 (1개)

Star Strider
Star Strider 2017년 9월 9일
You can create a matrix using a vector for ‘T0’ and the exponential function in ‘t’ using vector multiplication, then plot it as a function of ‘t’. For best results, the ‘t’ and ‘T0’ vectors have different lengths.
See if this does what you want:
k=1;
T0=linspace(20, 25, 5)'; % Column Vector Of ‘T0’ Values
Tm=25;
t=linspace(0,30,100); % Row Vector Of ‘t’ Values
T=Tm+(T0-Tm)*exp(-k*t);
plot(t,T)
axis([0 30 0 60])
Choose the range and number of values for ‘T0’.
The rest of your code is unchanged.

댓글 수: 2

Thank you very much!
As always, my pleasure!
If my Answer solved your problem, please Accept it!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2017년 9월 9일

댓글:

2017년 9월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by