How do I plot a function with a variable that has multiple values?
Mostra commenti meno recenti
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?
Risposte (1)
Star Strider
il 9 Set 2017
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 Commenti
Tyler Kelly
il 9 Set 2017
Star Strider
il 9 Set 2017
As always, my pleasure!
If my Answer solved your problem, please Accept it!
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!