Plotting Temperature as a function of y from an ODE

I need to plot T(y) and have the following, where y(4) is a solution taken from the ode solver. How do I call y(4) from my function into the T solution and then plot it as a funcion of y? Thanks!
t0=0; tf=7;
Pr = 0.6;
y0=[0 0 0.332 0 0.332*Pr^(1/3)]';
[t,y]=ode45(@ydotcalc,[t0 tf],y0);
figure(1)
plot(t,y);grid on
U_inf = 1; %Free stream velocity
T_s = 300; %Surface temperature Celsius
T_inf = 27; %Ambient temperature
v = 30E-6; %m^2/s
x = 0.5; %distance (m)
Re_x = U_inf*x/v; %Reynolds
T(y)=(((U_inf*v*x)^(1/2)*y(4))-T_s)/(T_inf-T_s);
figure(2)
plot(T,y);
function ydot = ydotcalc(t,y)
Pr = 0.6;
ydot = zeros(5,1);
ydot(1) = y(2);
ydot(2) = y(3);
ydot(3) = -0.5*y(1)*y(3);
ydot(4) = y(5);
ydot(5) = -0.5*Pr*y(1)*y(5);
end

Answers (1)

The ‘y’ matrix produced by the ode45 call is a (Nx5) matrix of column vectors. Also, since I assume that you want to plot ‘y(:,4)’ as a function of ‘T(y(:,4))’, try this:
T = @(y) ((sqrt(U_inf*v*x)*y)-T_s)/(T_inf-T_s);
figure(2)
plot(T(y(:,4)),y(:,4));
I created ‘T’ as an anonymous function, since you appear to refer to it as a function.
.

Asked:

on 29 Apr 2020

Answered:

on 29 Apr 2020

Community Treasure Hunt

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

Start Hunting!