Chapter9_Prob41
Chapter9_Prob41
clear all
Ts=-15; Ti=12;
alpha=0.138e-6;
x=1; t=2.592e6;
b=x/(2*sqrt(alpha*t));
T=Ts+(Ti-Ts)*2/pi*quad('exp(-x.^2)',0,b)
When the script file is executed, the following result is displayed in the Command Window:
T =
-3.3784
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis
for testing or instructional purposes only to students enrolled in courses for which the textbook
has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the
copyright owner is unlawful.
2
(b) The following MATLAB program in a script uses MATLAB’s built-in function quad to solve the
problem:
clear
Ts=-15; Ti=12;
alpha=0.138e-6;
x=0.5;
tdays=[0.01, 1:1:40]; %Starting with a value close to zero.
tsec=tdays*24*60*60;
b=x./(2*sqrt(alpha*tsec));
n=length(tsec);
for i=1:n
T(i)=Ts+(Ti-Ts)*2/sqrt(pi)*quad('exp(-x.^2)',0,b(i));
end
plot(tdays,T)
xlabel('Time (day)'), ylabel('Temperature (C)')
When the script file is executed, the following figure is displayed in the Figure Window:
14
12
10
8
Temperature (C)
−2
−4
−6
0 10 20 30 40
Time (day)
(c) The following MATLAB program in a script uses MATLAB’s built-in function quad to solve the
problem:
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis
for testing or instructional purposes only to students enrolled in courses for which the textbook
has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the
copyright owner is unlawful.
3
clear
Ts=-15; Ti=12;
alpha=0.138e-6;
x=[0.01 0.2:0.2:3]; %Starting with a value close to zero.
m=length(x);
tdays=[0.01, 1:1:30]; %Starting with a value close to zero.
tsec=tdays*24*60*60;
n=length(tsec);
[X,Y]=meshgrid(tdays,x);
for j=1:m
xa=x(j);
b=xa./(2*sqrt(alpha*tsec));
for i=1:n
T(j,i)=Ts+(Ti-Ts)*2/sqrt(pi)*quadl('exp(-xa.^2)',0,b(i));
end
end
%plot(tdays,T(j,:))
mesh(Y,X,T)
ylabel('Time (day)'), xlabel('Depth (m)')
zlabel('Temperature (C)')
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis
for testing or instructional purposes only to students enrolled in courses for which the textbook
has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the
copyright owner is unlawful.
4
When the script file is executed, the following figure is displayed in the Figure Window:
15
10
Temperature (C)
−5
−10
−15
30
20 3
Time (day) 2
10
1 Depth (m)
0 0
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis
for testing or instructional purposes only to students enrolled in courses for which the textbook
has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the
copyright owner is unlawful.