# Use ode45 when I have a constant that varies over time.

3 views (last 30 days)
Nicola De Noni on 16 May 2022
Commented: Nicola De Noni on 16 May 2022
Hi everyone, I’m trying to solve this differential equation (dT/dt):
dTdt = ((U*A)/(M_mix*cp_mix))*(T_in-T_out)/(log(T_in-T)/(T_out-T)); Where I want to see the temperature profile T as the weather changes. Unfortunately, T_in and T_out are two temperature vectors whose values vary over time. How can I solve this differential equation? This is my code:
function f = CalcoloSperimentale(t,T)
%% Parameters
n = 10; % length of time vector
M_mix = linspace(11379,11379,n); % Weigth [Kg]
cp_mix = linspace(2000,2000,n); % Cp
U = linspace(53,53,n); % Thermal coefficient [W/m2K]
A = linspace(25.2,25.2,n); % Area
xmin_in = 15; % Minimum inlet temperature
xmax_in = 16; % Maximum inlet temperature
T_in = xmin_in+rand(1,n)*(xmax_in-xmin_in);
xmin_out = 20; % Minimum outlet temperature
xmax_out = 40; % Maximum outlet temperature
T_out = linspace(xmax_out,xmin_out,n);
% Differential equation
dTdt(i) = ((U(i)*A(i))/(M_mix(i)*cp_mix(i)))*(T_in(i)-T_out(i))/(log(T_in(i)-T(i))/(T_out(i)-T(i)));
f = dTdt;
end
And the second script is:
n = 10;
timeStart = 0;
timeEnd = 5280;
timespan = linspace(timeStart,timeEnd,n);
% Initial condition
initT = 98.5+273.15;
[timeOut, T] = ode45(@CalcoloSperimentale, timespan, initT);
% Plotting data
plot(timeOut, T)
In order to solve this differential equation i should have to consider also the final condition of temperature, but i don't know hot to implement it.
##### 2 CommentsShowHide 1 older comment
Nicola De Noni on 16 May 2022
Absolutely! T_in is the inlet temperature of a chemical reactor jacket and T_out is the outlet temperature of the reactor jacket. I’m studying the heat transfer in a water-cooled tank. T is the temperature inside the vessel.
I would like to plot the temperature inside the reactor vs time (by knowing the inlet and outlet temperature of the cooling fluid) in order to understand the heat transfer.

Torsten on 16 May 2022
n=10;
xmin_in = 15; % Minimum inlet temperature
xmax_in = 16; % Maximum inlet temperature
T_in = xmin_in+rand(1,n)*(xmax_in-xmin_in);
xmin_out = 20; % Minimum outlet temperature
xmax_out = 40; % Maximum outlet temperature
T_out = linspace(xmax_out,xmin_out,n);
M_mix = 11379; % Weigth [Kg]
cp_mix = 2000; % Cp
U = 53; % Thermal coefficient [W/m2K]
A = 25.2; % Area
timeStart = 0;
timeEnd = 5280;
timespan = linspace(timeStart,timeEnd,n);
T_in = @(t)interp1(timespan,T_in,t);
T_out = @(t)interp1(timespan,T_out,t);
f = @(t,T) U*A/(M_mix*cp_mix)*(T_in(t)-T_out(t))/log((T_in(t)-T)/(T_out(t)-T));
% Initial condition
initT = 98.5+273.15;
[timeOut, T] = ode45(f, timespan, initT);
% Plotting data
plot(timeOut, T)
Nicola De Noni on 16 May 2022
You're right, i'm sorry! Anyway, thanks a lot!