Vous êtes sur la page 1sur 36

A Concise Introduction to MATLAB

by William J. Palm III


Solutions to Problems in Chapter Three
c
Solutions Manual Copyright 2007 The McGraw-Hill Companies. All rights
reserved. No part of this manual may be displayed, reproduced, or distributed
in any form or by any means without the written permission of the publisher
or used beyond the limited distribution to teachers or educators permitted by
McGraw-Hill for their individual course preparation. Any other reproduction
or translation of this work is unlawful.
Test Your Understanding Problems
T3.1-1 The session is
x = [5:20:85];
y = [10:30:130];
log(x.*y)-(log(x)+log(y))
ans =
1.0e-014 *
-0.0444 0 -0.1776 -0.1776 0.1776
which are essentially zero, so the identity is correct.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
T3.1-2 The session is
x = sqrt(2+6i)
x =
2.0402 + 1.4705i
abs(x)
ans =
2.5149
angle(x)
ans =
0.6245
real(x)
ans =
2.0402
imag(x)
ans =
1.4705
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
T3.1-3 The session is
x = [0:0.4:2*pi];
exp(i*x)-(cos(x)+i*sin(x))
The answers are essentially zero, which demonstrates that the identity is correct.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
T3.1-4 The session is
x = [0:0.4:2*pi];
asin(x)+acos(x)-pi/2
The answers are essentially zero, which demonstrates that the identity is correct.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
T3.1-5 The session is
x = [0:0.4:2*pi];
tan(2*x)-2*tan(x)./(1-tan(x).^2)
The answers are essentially zero, which demonstrates that the identity is correct.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
T3.1-6 The session is
x = [0:0.1:5];
sin(i*x)-i*sinh(x)
The answers are essentially zero, which demonstrates that the identity is correct.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
T3.1-7 The session is
x = [-10:0.1:10];
asinh(x)-log(x+sqrt(x.^2+1))
The answers are essentially zero, which demonstrates that the identity is correct.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
T3.2-1 The function le is
function y = f5(x)
y = exp(-0.2*x).*sin(x+2)-0.1;
You can plot the function to obtain solution estimates to use with fzero, or you can simply
try values of x between 0 and 10. The session is
fzero(@f5,0)
ans =
1.0187
fzero(@f5,4)
ans =
4.5334
fzero(@f5,6)
ans =
7.0066
So the solutions are x = 1.0187, 4.5334, and 7.0066.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
T3.2-2 The function le is
function y = f6(x)
y = 1 + exp(-0.2*x).*sin(x+2);
You can plot the function to obtain solution estimates to use with fminbnd, or you can
simply try values of x between 0 and 10. The session is
fminbnd(@f6,0,3)
ans =
2.5150
f6(ans)
ans =
0.4070
fminbnd(@f6,3,10)
ans =
8.7982
f6(ans)
ans =
0.8312
So the solutions are (x, y) = (2.5150, 0.4070) and (x, y) = (8.7982, 0.8312).
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
T3.2-3 Refer to Example 3.2-1. Modify the function le given in the example to use an
area of 200 ft
2
rather than 100 ft
2
. The function le is
function L = channel(x)
L = 200./x(1)-x(1)./tan(x(2))+2*x(1)./sin(x(2));
Because this problem is similar to Example 3.2-1, we can try the same guess as in the
example. The session is
x = fminsearch(@channel,[20,1])
x =
10.7457 1.0472
The answer is d = 10.7457 ft and = 1.0472 radians, or 60

.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
End-of-Chapter Problems
3.1 The session is
x = [0:2];
y = -3+i*x;
abs(y)
ans =
3.0000 3.1623 3.6056
sqrt(y)
ans =
0 + 1.7321i 0.2848 + 1.7553i 0.5503 + 1.8174i
(-5-7i)*y
ans =
5.0000 + 21.0000i 22.0000 + 16.0000i 29.0000 + 11.0000i
y/(6-3i)
ans =
-0.4000 - 0.2000i -0.4667 - 0.0667i -0.5333 + 0.0667i
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.2 The session is
x = -5-8i;y = 10-5i;
abs(x*y)
ans =
105.4751
angle(x*y)
ans =
-2.5930
abs(x/y)
ans =
0.8438
angle(x/y)
ans =
-1.6657
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.3 The session is
(180/pi)*atan2(8,5)
ans =
57.9946
(180/pi)*atan2(8,-5)
ans =
122.0054
(180/pi)*atan2(-8,5)
ans =
-57.9946
(180/pi)*atan2(-8,-5)
ans =
-122.0054
The answers are in degrees.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.4 The session is
x = [0:0.5:5];
sinh(x)-((exp(x)-exp(-x))/2)
ans =
0 0 0 0 0 0 0 0 0 0 0
Because the results are all zero, the identity is correct for the given values of x.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.5 The session is
x=[-100:10:100];
asinh(x)-log(x+sqrt(x.^2+1))
ans =
1.0e-011 *
Columns 1 through 7
-0.2842 0.2274 0.0853 0.0568 0 0 0
Columns 8 through 11
0 0 0 0
Because the results are all essentially zero, the identity is correct for the given values of x.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.6 The script le is
epsilon = 8.854e-12;
L = 1;r = 0.001;
d = input(

Enter a value for d in meters:

)
C = pi*epsilon*L./log((d-r)./r);
disp(

The capacitance in farads is:



)
disp(C)
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.7 The script le is
beta_deg = input(

Enter a value for beta in degrees:

);
% Convert to radians.
beta = (pi/180)*beta_deg;
mu = input(

Enter a value for mu:

);
F2 = input(

Enter a value for force F2:

);
F1 = F2*exp(mu*beta);
disp(

The force F1 is:

)
disp(F1)
The answer for = 130

, F
2
= 100, and = 0.3 is F
1
= 197.5217 N.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.8 The function le is
function angle_deg = atan2d(y,x)
% Computes atan2(y,x) in degrees.
angle_rad = atan2(y,x);
angle_deg = angle_rad*180/pi;
A test session follows.
atan2d(1,0))
ans =
90
atan2d(1,-1))
ans =
135
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.9 The function le is
function y = temp(x)
% Converts from Fahrenheit to Celsius.
y = (5/9)*(x-32);
A test session follows.
temp([32,212])
ans =
0 100
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.10 The function le is
function t = time(h,v0,g)
% Computes time t to reach a specified height h, with initial speed v0.
roots([0.5*g,-v0,h])
A test session follows.
time(100,50,9.81)
ans =
7.4612
2.7324
The smaller value is the time to reach the height while ascending; the larger value is the
time to reach the height while descending.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.11 The function les are
function h = height(V,r)
h = (V-2*pi*r.^3/3)./(pi*r.^2);
function cost = tower(r)
h = height(500,r);
cost = 600*pi*r.*h+800*pi*r.^2;
The session is:
optimum r = fminbnd(@tower,0,100)
optimum r =
4.9237
min cost = tower(optimum r)
min cost =
9.1394e+4
optimum h = height(500,optimum r)
optimum h =
3.2825
So the optimum radius is 4.9237 meters; the optimum height is 3.2825 meters, and the
minimum cost is $91,394.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.12 The function le is
function [L, total] = field(W,A)
L = (A-W.^2/8)./W;
total = 2*L+W+2*W/sqrt(2);
The session is:
[L, total] = field(6,80)
The results are L = 12.5833 meters and total = 39.6519 meters.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.13 The function le is
function cost = fence(R)
A = 1600;
L = (A-0.5*pi*R.^2)./(2*R);
cost = 30*(2*R+2*L)+40*pi*R;
The session is
optimum R = fminbnd(@fence,0,100)
optimum R =
18.6137
min cost = fence(optimum R)
min cost =
5.1575e+3
optimum L = (A-0.5*pi*optimum R.^2)./(2*optimum R)
optimum L =
28.3599
The optimum radius is 18.6137 feet, and the corresponding length is 28.3599 feet. The
minimum cost is $5,157.50.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.14 The function les are
function deltaV = volume(t)
global r x
V = 1e+9+1e+8*(1-exp(-t/100))-r*t;
deltaV = V-0.01*x*1e+9;
function time = decrease(x,r)
global r x
time = fzero(@volume,1);
The session is
time = decrease(50,1e+7)
time =
54.1832
Thus it will take about 54 days.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.15 a)
h =
3V
r
2
A = r

r
2
+
9V
2

2
r
4
b) The function le is
function A = area(r)
global V
A = pi*r.*sqrt(r.^2+9*V^2./(pi^2*r.^4));
c) First plot the area versus r to locate the minimum approximately. It is between r = 1
and r = 3. The session is
global V
V = 10;
r = [0.5:0.01:5];
plot(r,area(r))
[r, A] = fminbnd(@area,1,3);
h = 3*V/(pi*r^2)
The results are r = 1.8901, A = 19.4393, and h = 2.6730.
Plotting A versus r shows that A is 10% above its minimum value when r is approxi-
mately 1.48 and 2.35.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.16 a) The function is
function [V, A] = torus(a,b)
V = 0.25*pi^2*(a+b).*(b-a).^2;
A = pi^2*(b.^2-a.^2);
The session is
a = [0.25:0.01:4];
b = a+2;
[V,A] = torus(a,b);
subplot(2,1,1),plot(a,V),xlabel(

a (in.)

),ylabel(

V (cu. in.)

)
subplot(2,1,2),plot(a,A),xlabel(

a (in.)

),ylabel(

A (sq. in.)

)
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.17 The function is
function [a,b,c,d] = cubicpoly(x,y)
for k = 1:4
A(:,k) = x.^(4-k);
end
B = y

;
coeff = A\B;
a = coeff(1);
b = coeff(2);
c = coeff(3);
d = coeff(4);
The session is
x = [-2,0,2,4];
y = [-20,4,68,508];
[a,b,c,d] = cubicpoly(x,y)
This gives the correct answers.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.18 The script le is
ex = @(x) 10*exp(-2*x);
x = [0:0.01:2];
plot(x,ex(x)),xlabel(

),ylabel(

10e^{-2x}

)
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.19 The script le is
fn = @(x) 20*x.^2-200*x + 3;
x = [4:0.01:6];
plot(x,fn(x)),xlabel(

),ylabel(

),grid
[x, fval] = fminbnd(fn,4,6)
The answers returned are x = 5, which is the location of the minimum value, and fval =
-497, which is the value of the minimum.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.20 The script le is
f = @(x) x.^2;
g = @(x) 3*cos(x);
h = @(x) 6*exp(x);
u = @(x) h(g(f(x)));
x = [0:0.01:4];
plot(x,u(x)),xlabel(

),ylabel(

)
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.21 Create the following function le.
function f = cubic(a,b,c,d)
f = @p;
function y = p(x)
y = a*x.^3+b*x.^2+c*x+d;
end
end
The session is
>> f = cubic(3,-12,-33,90);
x = [-10:0.01:10];
plot(x,f(x)),grid
fzero(f,-4)
fzero(f,6)
The returned answers are 3 and 5. The two zeros are located at x = 3 and x = 5.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.22 Create the following function le.
function f = parabola(a,b,c)
f = @p;
function y = p(x)
y = a*x.^2+b*x+c;
end
end
The session is
f = parabola(4,-50,5);
[x,fval] = fminbnd(f,-10,10)
The returned answers are x = 6.2500, which is the location of the minimum, and fval =
-151.2500, which is the value of the minimum.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.23 Assuming the data has been stored in the text le Prob3p24.txt, the session is
load Prob3p24.txt
A = Prob3p24;
mean(A)
The returned answers are 56.7500 42.2500 94.2500.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.24 Assuming that the data have been saved in the Excel spreadsheet le Prob3p24.xls,
the session is
A = xlsread(

Prob3p24

)
A =
55 42 98
51 39 95
63 43 94
58 45 90
S = sum(A)
S =
227 169 377
The sums are 227, 169, and 377.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.
3.25 No MATLAB commands are needed to solve this problem.
This work may be used only on a not-for-prot basis and only by instructors
in courses for which the textbook has been adopted. Any other use without
publishers consent is unlawful.

Vous aimerez peut-être aussi