%function ThermalModel %Not needed or cannot be used in this context.
% Approximate the analytical solution of the heat equation with a heat
% source in the center of a block.
% System parameters.
H = 6; % the block height (mm)
L = 40; % the block length (mm)
W = 50; % the block width (mm)
kAl = 0.25; % Aluminum thermal conductivity (W/(mm*K))
c = 897; % Aluminum specific heat capacity (J/(kg * K)).
rho = 2.7E-6; % Density (kg/mm^3).
alpha = kAl / (c * rho); % Thermal diffusivity (mm^2/s).
Qi = 2 * 27 / 300; % Input power per unit volume length (?).
dx = 0.2;
dt = .2;
x = 0:dx:L;
tmax = 10;
t = 0:dt:tmax;
% Approximate heat equation using Fourier series and Duhamel's Principle.
ds = 0.1;
N = 200;
n = 1:N;
b = 2*Qi*sin(n*pi/2)/(c*rho*L);
% As N goes to infinity, the solution
% approximates a triangle function centered on L/2. Because we can't go to
% infinity, there will always be a sharp spike at x = L/2.
u = zeros(length(x), length(t));
for xi = 1:length(x)
for ti = 1:length(t)
tc = t(ti);
for ni = 1:length(n)
s = 0:ds:tc;
sint = 0;
for si = 1:length(s)
sint = sint + b(ni)*exp(-alpha*(n(ni)*pi/L)^2*(tc-s(si)))*ds;
end
u(xi, ti) = u(xi, ti) + sin(n(ni)*pi*x(xi)/L) * sint;
end
end
end
figure;
mesh(t, x, u);
ylabel('x (mm)');
xlabel('t (s)');
zlabel('Temperature (deg C)');
title('Approximation to heat equation solution with constant heat source at L/2, using Fourier series');
% Approximate solution using Green's function. Note that as ds -> zero,
% the solution approximates a triangle function centered at L/2, and
% increasing asymptotically over time.
u = zeros(length(x), length(t));
N = 40;
n = -N:N;
ds = 0.01;
for xi = 1:length(x)
for ti = 1:length(t)
tc = t(ti);
if tc == 0
continue;
end
s = 0:ds:(tc-ds);
for si = 1:length(s)
nint = 0;
for ni = 1:length(n)
nint = nint + exp(-(x(xi)-2*n(ni)*L-L/2)^2/(4*alpha*(tc-s(si)))) - ...
exp(-(x(xi)-2*n(ni)*L+L/2)^2/(4*alpha*(tc-s(si))));
end
u(xi, ti) = u(xi, ti) + ...
(Qi/(c*rho)) * nint * ds / sqrt(4*pi*alpha*(tc-s(si)));
end
end
end
figure;
mesh(t, x, u);
ylabel('x (mm)');
xlabel('t (s)');
zlabel('Temperature (deg C)');
title('Approximation to heat equation solution with constant heat source at L/2, using Green''s function');
%return;
fixed program to run in matlab without error