Use ode45 when I have a constant that varies over time.
3 views (last 30 days)
Show older comments
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.
Thanks for the answers!
Accepted Answer
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)
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!