Grey box model of 1d heat diffusion in a rod (official mathworks example)
5 views (last 30 days)
Show older comments
Hello,
I'm thinking about grey-box modelling of heat diffusion in a rod with the 1d heat equation.
There is a interesting example at mathworls side:
I would adapt the example (image: original) and change it a little bit to include a a convection to air at the left end of the rod (image: adapted).

Here is the code for the original version with the insulation at one end:
function [A,B,C,D,K,x0] = heatd(kappa,htf,T,Ngrid,L,temp)
% ODE file parameterizing the heat diffusion model
% kappa (first parameter) - heat diffusion coefficient
% htf (second parameter) - heat transfer coefficient
% at the far end of rod
% Auxiliary variables for computing state-space matrices:
% Ngrid: Number of points in the space-discretization
% L: Length of the rod
% temp: Initial room temperature (uniform)
% Compute space interval
deltaL = L/Ngrid;
% A matrix
A = zeros(Ngrid,Ngrid);
for kk = 2:Ngrid-1
A(kk,kk-1) = 1;
A(kk,kk) = -2;
A(kk,kk+1) = 1;
end
% Boundary condition on insulated end
A(1,1) = -1; A(1,2) = 1;
A(Ngrid,Ngrid-1) = 1;
A(Ngrid,Ngrid) = -1;
A = A*kappa/deltaL/deltaL;
% B matrix
B = zeros(Ngrid,1);
B(Ngrid,1) = htf/deltaL;
% C matrix
C = zeros(1,Ngrid);
C(1,1) = 1;
% D matrix (fixed to zero)
D = 0;
% K matrix: fixed to zero
K = zeros(Ngrid,1);
% Initial states: fixed to room temperature
x0 = temp*ones(Ngrid,1);
This section should be altered, but I'm not sure how to do it to include a known htc for air at the right end.
% Boundary condition on insulated end
A(1,1) = -1; A(1,2) = 1;
A(Ngrid,Ngrid-1) = 1;
A(Ngrid,Ngrid) = -1;
A = A*kappa/deltaL/deltaL;
Then the idgrey object is constructed:
m = idgrey('heatd',{0.27 1},'c',{10,1,22});
Another thing I don't get is the structure of data. Unfortunately there is no explanation or example shown.
How can I implement my temperature data (for three points as two column table (t,T1) , (t,T2), (t,T3)) in the greyest?
me = greyest(data,m)
If I get it right, the parameters heat diffusion coefficient and heat transfer coefficient at the right end of rod are estimated, but I have to guess them as initial starting point? To do this the transient temperature data is required, unfortunately the example is incomplete.
0 Comments
Accepted Answer
Torsten
on 9 Feb 2025
Edited: Torsten
on 9 Feb 2025
I think it will be simpler to couple "pdepe" for the solution of your PDE and "lsqnonlin" for optimizing your model parameters.
Maybe I'm wrong, but using "idgrey" for only 3 measurement points will force Ngrid = 3 which gives an insufficient resolution of the spatial temperature distribution.
Further, I find it hard to understand how to use "idgrey".
7 Comments
Torsten
on 12 Feb 2025
Edited: Torsten
on 12 Feb 2025
Tdata=xlsread('TempData.xlsx');
time=Tdata(:,1);
T1=Tdata(:,3); % at x1=0;
T2=Tdata(:,5); % at x2=0.5;
T3=Tdata(:,7); % at x3=L;
TinterpT1 = @(t)interp1(time,T1,t);
TinterpT3 = @(t)interp1(time,T3,t);
L=1;
tsim=200;
nx=100;
dx=L/nx;
nt=200;
dt=tsim/nt;
x=linspace(0,L,nx);
t=linspace(1,tsim,nt);
Tini=300; % initial temperature at t= 0 s
rho=7850; % density
cp=420; % heat capacity
lambda=45; % conductivity
m = 0;
sol = pdepe(m,@(x,t,u,dudx)heatequation(x,t,u,dudx,rho,cp,lambda),...
@(x)ic(x,Tini),@(xl,ul,xr,ur,t)bc(xl,ul,xr,ur,t,TinterpT1,TinterpT3),x,t);
u = sol(:,:,:);
plot(x,u(end,:))
function [c,f,s]=heatequation(x,t,u,dudx,rho,cp,lambda)
c = rho*cp;
f = lambda*dudx;
s = 0;
end
function u0=ic(x,Tini)
u0 = Tini;
end
function [pl,ql,pr,qr]=bc(xl,ul,xr,ur,t,TinterpT1,TinterpT3)
pl = ul - TinterpT1(t); % BC left, convection to a streaming fluid h_fluid=unknown
ql = 0; %
pr = ur - TinterpT3(t); % BC right, convection to a streaming fluid h_air=known %
qr = 0;
end
Torsten
on 13 Feb 2025
Edited: Torsten
on 13 Feb 2025
As you can see from the results of the simulation with "pdepe", you will never get the T2 trajectory of your measurements when you use the partial differential equation as suggested by the model equation. The thermal mass of the rod is far too large to cool down within 200 seconds with the material data given. The plot above shows that after 200 seconds, the temperature in measurement point x2 still remains almost unchanged at Tini = 300 K.
More Answers (0)
See Also
Categories
Find more on Heat Exchangers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!