Solution Practice Set A
Solution Practice Set A
Solution Practice Set A
Practice Sets
Practice Set A
Problem 1
(a)
1111 - 345
ans =
766
(b)
format long; [exp(14), 382801*pi]
ans =
1.0e+006 *
1.20260428416478 1.20260480938683
ans =
2.64550781250000 2.64575000000000 2.64575163398693
2.64575131106459
235
236 Solutions to the Practice Sets
Problem 2
(a)
cosh(0.1)
ans =
1.00500416805580
(b)
log(2)
ans =
0.69314718055995
(c)
atan(1/2)
ans =
0.46364760900081
format short
Problem 3
[x, y, z] = solve(’3*x + 4*y + 5*z = 2’, ’2*x - 3*y + 7*z = -
1’, ’x - 6*y + z = 3’, ’x’, ’y’, ’z’)
x =
241/92
y =
-21/92
z =
-91/92
ans =
[ 2]
Practice Set A 237
[ -1]
[ 3]
It checks!
Problem 4
[x, y, z] = solve(’3*x - 9*y + 8*z = 2’, ’2*x - 3*y + 7*z = -
1’, ’x - 6*y + z = 3’, ’x’, ’y’, ’z’)
x =
39/5*y+22/5
y =
y
z =
-9/5*y-7/5
ans =
[ 2]
[ -1]
[ 3]
Problem 5
syms x y; factor(xˆ4 - yˆ4)
ans =
(x-y)*(x+y)*(x^2+y^2)
238 Solutions to the Practice Sets
Problem 6
(a)
simplify(1/(1 + 1/(1 + 1/x)))
ans =
(x+1)/(2*x+1)
(b)
simplify(cos(x)ˆ2 - sin(x)ˆ2)
ans =
2*cos(x)^2-1
better =
cos(2*x)
how =
combine
Problem 7
3ˆ301
ans =
4.1067e+143
sym(’3’)ˆ301
ans =
4106744371757651279739780821462649478993910868760123094144405
7023510699153249722978140061846706682416475145332179398212844
0538198297087323698003
ans =
3^301
This does not work because sym, by itself, does not cause an evaluation.
Problem 8
(a)
solve(’8*x + 3 = 0’, ’x’)
ans =
-3/8
(b)
vpa(ans, 15)
ans =
-.375000000000000
(c)
syms p q; solve(’xˆ3 + p*x + q = 0’, ’x’)
ans =
[
1/6*(-108*q+12*(12*p^3+81*q^2)^(1/2))^(1/3)-2*p/(-
108*q+12*(12*p^3+81*q^2)^(1/2))^(1/3)]
[ -1/12*(-108*q+12*(12*p^3+81*q^2)^(1/2))^(1/3)+p/(-
108*q+12*(12*p^3+81*q^2)^(1/2))^(1/3)+1/2*i*3^(1/2)*(1/6*(-
108*q+12*(12*p^3+81*q^2)^(1/2))^(1/3)+2*p/(-
108*q+12*(12*p^3+81*q^2)^(1/2))^(1/3))]
[ -1/12*(-108*q+12*(12*p^3+81*q^2)^(1/2))^(1/3)+p/(-
108*q+12*(12*p^3+81*q^2)^(1/2))^(1/3)-1/2*i*3^(1/2)*(1/6*(-
108*q+12*(12*p^3+81*q^2)^(1/2))^(1/3)+2*p/(-
108*q+12*(12*p^3+81*q^2)^(1/2))^(1/3))]
(d)
ezplot(’exp(x)’); hold on; ezplot(’8*x - 4’); hold off
240 Solutions to the Practice Sets
8 x−4
40
20
–20
–40
–60
–6 –4 –2 0 2 4 6
x
ans =
0.7700
ans =
2.9929
Problem 9
(a)
ezplot(’xˆ3 - x’, [-4 4])
3
x −x
60
40
20
–20
–40
–60
–4 –3 –2 –1 0 1 2 3 4
x
Practice Set A 241
(b)
ezplot(’sin(1/xˆ2)’, [-2 2])
2
sin(1/x )
0.8
0.6
0.4
0.2
–0.2
–0.4
–0.6
–0.8
–1
X = -2:0.1:2;
plot(X, sin(1./X.ˆ2))
0.8
0.6
0.4
0.2
–0.2
–0.4
–0.6
–0.8
–1
–2 –1.5 –1 –0.5 0 0.5 1 1.5 2
This picture is incomplete. Let’s see what happens if we refine the mesh.
0.8
0.6
0.4
0.2
–0.2
–0.4
–0.6
–0.8
–1
–2 –1.5 –1 –0.5 0 0.5 1 1.5 2
tan(x/2)
10
–2
–4
–6
–8
–10
–3 –2 –1 0 1 2 3
x
(d)
X = -2:0.05:2;
plot(X, exp(-X.ˆ2), X, X.ˆ4 - X.ˆ2)
Practice Set A 243
12
10
–2
–2 –1.5 –1 –0.5 0 0.5 1 1.5 2
Problem 10
Let’s plot 2x and x 4 and look for points of intersection. We plot them first
with ezplot just to get a feel for the graph.
2x
50
45
40
35
30
25
20
15
10
−6 −4 −2 0 2 4 6
x
Note the large vertical range. We learn from the plot that there are no points
of intersection between 2 and 6 or −6 and −2; but there are apparently two
points of intersection between −2 and 2. Let’s change to plot now and focus
on the interval between −2 and 2. We’ll plot the monomial dashed.
16
14
12
10
0
−2 −1.5 −1 −0.5 0 0.5 1 1.5 2
We see that there are points of intersection near −0.9 and 1.2. Are there any
other points of intersection? To the left of 0, 2x is always less than 1, whereas
x 4 goes to infinity as x goes to −∞. However, both x 4 and 2x go to infinity as
x goes to ∞, so the graphs may cross again to the right of 6. Let’s check.
5
x 10
12
10
0
6 8 10 12 14 16 18 20
We see that they do cross again, near x = 16. If you know a little calculus,
you can show that the graphs never cross again (by taking logarithms, for
example), so we have found all the points of intersection. Now let’s use
fzero to find these points of intersection numerically. This command looks
for a solution near a given starting point. To find the three different points of
Practice Set A 245
intersection we will have to use three different starting points. The graphical
analysis above suggests appropriate starting points.
r1 =
-0.8613
r2 =
1.2396
r3 =
16
ans =
2.2204e-016
ans =
-8.8818e-016
ans =
0
symroots =
[ -4*lambertw(-1/4*log(2))/log(2)]
[ 16]
[ -4*lambertw(-1/4*i*log(2))/log(2)]
246 Solutions to the Practice Sets
[ -4*lambertw(1/4*log(2))/log(2)]
[ -4*lambertw(1/4*i*log(2))/log(2)]
In fact we get the three real solutions already found and two complex solutions.
double(symroots)
ans =
1.2396
16.0000
-0.1609 + 0.9591i
-0.8613
-0.1609 - 0.9591i
Only the real solutions correspond to points where the graphs intersect.
Practice Set B
Problem 1
(a)
[X, Y] = meshgrid(-1:0.1:1, -1:0.1:1); contour(X, Y, 3*Y +
Y.ˆ3 - X.ˆ3, ’k’)
0.8
0.6
0.4
0.2
−0.2
−0.4
−0.6
−0.8
−1
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1