How do i use ode23 if i have a spline function?

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?

 채택된 답변

Torsten
Torsten 2022년 4월 1일
편집: Torsten 2022년 4월 1일

0 개 추천

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

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 2022년 4월 2일
편집: Torsten 2022년 4월 2일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interpolation에 대해 자세히 알아보기

제품

릴리스

R2021b

태그

질문:

2022년 4월 1일

편집:

2022년 4월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by