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?

Respuestas (1)

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 comentarios

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

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 9 de Sept. de 2017

Comentada:

el 9 de Sept. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by