Chapter8

Click here to see book problems

Problem 20
Script file:

%problem 20
figure
x= [-5 -4 -1 1 4 6 9 10];
y= [ 12 10 6 2 -3 -6 -11 -12];
p1=polyfit(x,y,1);
xplot=linspace(-5,10,100);
yplot=polyval(p1,xplot);
plot(x,y,’ok’,xplot,yplot,’k’)
grid on
xlabel(‘x’)
ylabel(‘y’)

Problem 21
Script file:

%problem 21
figure
hsi=[-1000 0 3000 8000 15000 22000 28000];
Tsi=[213.9 212 206.2 196.2 184.4 172.6 163.1];
p=polyfit(hsi,Tsi,1);
T5000=polyval(p,16000);
xplot=linspace(-1000,28000,100);
yplot=polyval(p,xplot);
plot(hsi,Tsi,’ok’,xplot,yplot,’b’)
grid on
xlabel(‘h (m)’)
ylabel(‘T (Deg C)’)

Problem 22
Script file:

%problem 22
figure
Y=[1815 1845 1875 1905 1935 1965];
t=Y-1800;
Pop=[8.3 19.7 44.4 83.3 127.1 190.9];
p=polyfit(t,Pop,2);
tp=linspace(1815,1965,100);
Pplot=polyval(p,tp-1800);
plot(Y,Pop,’o’,tp,Pplot)
grid on
xlabel(‘Year’)
ylabel(‘Population (Millions)’)
legend(‘Data’,’Model’,’location’,’north’)
Pop1915=polyval(p,1915-1800);

Problem 23
Script file:

%problem 23
figure
t=[0 1 3 4 6 7 9];
NB = [500 600 1000 1400 2100 2700 4100];
p=polyfit(t,log(NB),1);
m=p(1);
b=exp(p(2));
tp=linspace(0,9,100);
F=@ (x) b*exp(m*x);
NBp=F(tp);
plot(t,NB,’o’,tp,NBp)
title(‘Problem 23’)
grid on
xlabel(‘t (hr)’)
ylabel(‘NB’)
legend(‘Data’,’Model’,’location’, ‘NorthWest’)
NB45=F(5);

Problem 24
Script file:

%problem 24
figure
C=102;
w=[7:14:91];
H = [8.5 21 50 77 89 98 99];
%also can use y = log(H./(C-H));
y=C./H-1;
p=polyfit(w,log(y),1);
B=-p(1)
A=exp(p(2))
wp=linspace(7,91,100);
F=@ (x) C./(1+A*exp(-B*x));
Hp=F(wp);
plot(w,H,’o’,wp,Hp)
title(‘Problem 24’)
xlabel(‘t (Days)’)
ylabel(‘Height (in)’)
legend(‘Data’,’Model’,’location’, ‘NorthWest’)
grid on
Height_day_40 = F(40)

Problem 25
Script file:

%problem 25
w=[7:14:91];
H = [8.5 21 50 77 89 98 99];
% Part (a)

disp(‘Part (a)’)
p=polyfit(w,H,3);
wp=linspace(7,91,100);
Hp=polyval(p,wp);
figure

plot(w,H,’o’,wp,Hp)
grid on

xlabel(‘t (Day)’)
ylabel(‘Height (in)’)
legend(‘Data’,’Model’,’location’, ‘NorthWest’)
title(‘Problem 25 part (a)’)

H_Day_40_Part_a = polyval(p,40)
% Part (b)

disp(‘Part (b)’)
wp=linspace(7,91,100);
HpLin=interp1(w,H,wp,’linear’);
HpSpl=interp1(w,H,wp,’spline’);
figure

plot(w,H,’o’,wp,HpLin,wp,HpSpl)
grid on
xlabel(‘t (Days)’)
ylabel(‘Height (in)’)
legend(‘Data’,’Linear Interpolation’,’Spline Interpolation’,’location’, ‘NorthWest’)
title(‘Problem 25 part (b)’)
H40_Part_bLinear=interp1(w,H,40,’linear’)
H40_Part_bSpline=interp1(w,H,40,’spline’)

Problem 26
Script file:

%problem 26
%part a
x=[1 2.2 3.7 6.4 9 11.5 14.2 17.8 20.5 23.2];
y=[12 9 6.6 5.5 7.2 9.2 9.6 8.5 6.5 2.2];
p1=polyfit(x,y,1);
xplot=linspace(0,24,100);
yplot=polyval(p1,xplot);
figure
plot(x,y,’ok’,xplot,yplot,’k’,’linewidth’,2,’markersize’,8)
grid on
xlabel(‘x’,’fontsize’,18)
ylabel(‘y’,’fontsize’,18)

%part b
x=[1 2.2 3.7 6.4 9 11.5 14.2 17.8 20.5 23.2];
y=[12 9 6.6 5.5 7.2 9.2 9.6 8.5 6.5 2.2];
p1=polyfit(x,y,2);
xplot=linspace(0,24,100);
yplot=polyval(p1,xplot);
figure
plot(x,y,’ok’,xplot,yplot,’k’, ‘linewidth’,2,’markersize’,8)
grid on
xlabel(‘x’,’fontsize’,18)
ylabel(‘y’,’fontsize’,18)

%part c
x=[1 2.2 3.7 6.4 9 11.5 14.2 17.8 20.5 23.2];
y=[12 9 6.6 5.5 7.2 9.2 9.6 8.5 6.5 2.2];
p1=polyfit(x,y,3);
xplot=linspace(0,24,100);
yplot=polyval(p1,xplot);
figure
plot(x,y,’ok’,xplot,yplot,’k’, ‘linewidth’,2,’markersize’,8)
grid on
xlabel(‘x’,’fontsize’,18)
ylabel(‘y’,’fontsize’,18)

%part d
x=[1 2.2 3.7 6.4 9 11.5 14.2 17.8 20.5 23.2];
y=[12 9 6.6 5.5 7.2 9.2 9.6 8.5 6.5 2.2];
p1=polyfit(x,y,5);
xplot=linspace(0,24,100);
yplot=polyval(p1,xplot);
figure
plot(x,y,’ok’,xplot,yplot,’k’, ‘linewidth’,2,’markersize’,8)
grid on
xlabel(‘x’,’fontsize’,18)
ylabel(‘y’,’fontsize’,18)

Problem 27
Script file:

%problem 27
%part a
figure
h=0:3000:33000;
Den=[1.2 0.91 0.66 0.47 0.31 0.19 0.12 0.075 0.046 0.029 0.018 0.011];
plot(h, Den,’ok’)
xlabel(‘\fontsize{16}Height (m)’)
ylabel(‘\fontsize{16}Density (kg/m^3)’)
grid on
figure
semilogx(h, Den,’ok’)
xlabel(‘\fontsize{16}Height (m)’)
ylabel(‘\fontsize{16}Density (kg/m^3)’)
grid on
figure
semilogy(h, Den,’ok’)
xlabel(‘\fontsize{16}Height (m)’)
ylabel(‘\fontsize{16}Density (kg/m^3)’)
grid on
figure
loglog(h, Den,’ok’)
xlabel(‘\fontsize{16}Height (m)’)
ylabel(‘\fontsize{16}Density (kg/m^3)’)

%part b
figure
h=0:3000:33000;
Den=[1.2 0.91 0.66 0.47 0.31 0.19 0.12 0.075 0.046 0.029 0.018 0.011];
p=polyfit(h,log(Den),1);
m=p(1)
b=exp(p(2))
heq=linspace(0,33000,100);
Deq=b*exp(m*heq);
plot(h, Den,’ok’,heq,Deq,’k’)
title(‘Problem 27 (b)’)
xlabel(‘\fontsize{16}Height (m)’)
ylabel(‘\fontsize{16}Density (kg/m^3)’)
grid on

Problem 28
Script file:

%problem 28
x=[0.4 2.2 3.1 5.0 6.6 7.6];
y=[1.7 10.1 26.9 61.2 158 398];
p = polyfit(x,log(y),1);
m = p(1);
b = exp(p(2));
xplot = linspace(0.5,7.8,100);
yplot = b*exp(m*xplot);
plot(x,y,’ok’,xplot,yplot,’k’,’linewidth’,2,’markersize’,8)
title(‘Problem 25’)
xlabel(‘x’,’fontsize’,18)
ylabel(‘y’,’fontsize’,18)
grid on

Problem 29
Script file:

%problem 29
figure
T = [2 4 6 8 10 20 40 60 80 100 150 250 350 500 1000 1400];
TC = [46 300 820 1560 2300 5000 3500 2100 1350 900 400 190 120 75 30 20];
% %part a
loglog(T, TC, ‘o’)
title(‘Problem 29 (a)’)
xlabel(‘Temperature (k)’)
ylabel(‘Conductivity (W/m-K)’)
grid on
%part b
figure
TCL = log10(TC);
TL = log10(T);
pa = polyfit(TL, TCL, 2);
FTCf2 =@ (x) 10.^(pa(1)*log10(x).^2+pa(2)*log10(x)+pa(3));
Tp = 2:1400;
TCp2 = FTCf2(Tp);
loglog(T,TC,’o’,Tp,TCp2)
title(‘Problem 29(b)’)
xlabel(‘Temperature (k)’)
ylabel(‘Conductivity (W/m-K)’)
legend(‘Data’,’Curve fit 2nd order polynomial’, ‘location’, ‘South’)
grid on
%part c

pb = polyfit(TL, TCL, 3);
FTCf3 = @ (x) 10.^(pb(1)*log10(x).^3+pb(2)*log10(x).^2+pb(3));
TCp3 = FTCf3(Tp);
figure
loglog(T,TC,’o’,Tp,TCp3)
title(‘Problem 29 (c)’)
xlabel(‘Temperature (K)’)
ylabel(‘Conductivity (W/m-K)’)
legend(‘Data’,’Curve fit 3rd order polynomial’)
grid on

Problem 30
Script file:

%problem 30
figure
t = 0.5:0.5:6;
C=[1.7 3.1 5.7 9.1 6.4 3.7 2.8 1.6 1.2 0.8 0.7 0.6];
Cf=1./C;
%part a
disp(‘Part (a)’)
pa=polyfit(t,Cf,2);
tp=linspace(0.5,6,100);
Cpa=1./polyval(pa,tp);
plot(t,C,’o’,tp,Cpa)
xlabel(‘t (h)’)
ylabel(‘C ((gr/L)’)
legend(‘Data’,’Model’,’location’,’NorthEast’)
title(‘Problem 30 part(a)’)
grid on
%part b
disp(‘Problem 30 part (b)’);
figure
pb = polyfit(t,Cf,3);
Cpb=1./polyval(pb,tp);
plot(t,C,’o’,tp,Cpb)
xlabel(‘t (h)’)
ylabel(‘c (gr/L)’)
legend(‘Data’, ‘Model’, ‘location’, ‘NorthEast’)
title(‘Problem 30 part(b)’)
grid on