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
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 件のコメント
Tyler Kelly
2017 年 9 月 9 日
Star Strider
2017 年 9 月 9 日
As always, my pleasure!
If my Answer solved your problem, please Accept it!
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!