Figure 3.13:

Transient heating of slab, cylinder, and sphere.

Code for Figure 3.13

Text of the GNU GPL.

main.m


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
%
% plot the transient
% sin(r)/r series solution
% of spherical heat conduction problem
%
% jbr, 11/13/2009
%

nterms = 100;
nrs = 100;
r  = linspace(0, 1, nrs)';

tvec = [0.0001, 0.001, 0.01, 0.1, 0.5];
Temp = zeros(nrs, numel(tvec));
sign = 1;
for n  = 1: nterms
  term = sign*sin(n*pi*r)./(n*pi*r)*exp(-(n*pi)^2*tvec);
  % take limit at r=0
  if (r(1) == 0 )
    term(1,:) = sign*exp(-(n*pi)^2*tvec);
  end
  Temp += term;
  sign = -sign;
end
Temp = 1 - 2*Temp;

figure()
plot(r,Temp)

output = [r, Temp];
save transsph.dat output;