I am working on a program in which we must use ode23 to solve Newton's Law of Cooling where k is a changing value interpolated a a specific time in a data table of tvalues and k values. I have used cubic splines to get k-values but now i need to solve the differential equation dT/dt = k(T-Ta). I am given T and Ta as well. I have written for the spline,
xx = linspace(1, tf);
pp = spline(t,k);
yy = ppval(pp,xx);
what do i need to plug in to get a plottable solution with ode23?

 Akzeptierte Antwort

Torsten
Torsten am 1 Apr. 2022
Bearbeitet: Torsten am 1 Apr. 2022

0 Stimmen

Ta = 273.15 + 10;
fun = @(tt) ppval(spline(t,k),tt);
fun_ode23 = @(t,T) fun(t)*(T-Ta);
T0 = 273.15 + 50;
tspan = [0,1];
[t,T] = ode23(fun_ode23,tspan,T0)
plot(t,T)

2 Kommentare

Thank you. In the case of this project, the data runs from time 1-10. t from 0 to 1 is constant k=-0.3. t after 10 is constant k=-0.2. i understand if the stopping time is between zero and one i can replace fun(t) with the constant value. do i do the same for after 10 seconds?
Torsten
Torsten am 2 Apr. 2022
Bearbeitet: Torsten am 2 Apr. 2022
Ta = 273.15 + 10;
T0 = 273.15 + 50;
tspan = [0,20];
fun_k = @(tt) ppval(spline(t,k),tt);
[t,T] = ode23(@(t,T)fun_ode23(t,T,Ta,fun_k),tspan,T0);
plot(t,T)
function dTdt = fun_ode23(t,T,Ta,fun_k)
if t <=1
k = -0.3;
elseif t > 1 && t <=10
k = fun_k(t);
else
k = -0.2;
end
dTdt = k*(T-Ta);
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interpolation finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2021b

Gefragt:

am 1 Apr. 2022

Bearbeitet:

am 2 Apr. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by