% Problem 5
clear
close all
% We begin by graphing x^4 and 2^x on the interval [-10, 10].
ezplot('x^4', [-10, 10])
hold on
ezplot('2^x', [-10, 10])
hold off
title 'Figure 5.1'
pause
print -deps figA5-1
% This graph appears in Figure 5.1.
% There appear to be points of intersection between -2 and 2, but none between
% 2 and 10 nor between -10 and -2. Let's plot on [-2, 2] to get a clearer
% picture.
ezplot('x^4', [-2, 2])
hold on
ezplot('2^x', [-2, 2])
hold off
title 'Figure 5.2'
pause
print -deps figA5-2
% This graph appears in Figure 5.2.
% We see that there is one point of intersection at about -0.9, and another
% near 1.2. Are there other points of intersection? To the left of 0, 2^x is
% always less than 1, whereas x^4 goes to infinity as x goes to -infinity. On
% the other hand, both x^4 and 2^x go to infinity as x goes to infinity, so
% the graphs may intersect again to the right of 0. Let's check.
ezplot('x^4', [10, 20])
hold on
ezplot('2^x', [10, 20])
hold off
title 'Figure 5.3'
pause
print -deps figA5-3
% This graph appears in Figure 5.3.
% We see that they do cross again, near x = 16. Using calculus you can show that
% the graphs never cross again (by taking logarithms, for example), so we have
% found all the points of intersection. Low let's use the fzero command to
% find these points of intersection numerically.
r1 = fzero('x^4 - 2^x', -0.9)
r1 =
-0.8613
r2 = fzero('x^4 - 2^x', 1.2)
r2 =
1.2396
r3 = fzero('x^4 - 2^x', 16)
r3 =
16
% Let's see if the r1, r2, and r3 satisfy the equation.
r1^4 - 2^r1
ans =
-1.1102e-016
r2^4 - 2^r2
ans =
4.4409e-016
r3^4 - 2^r3
ans =
0
% We see that r1 and r2 very nearly satisfy the equation (as we expect for
% very accurate numerical solutions), and that r3 = 16 satisfies the equation
% exactly. It is easily seen that 16 is an exact solution.
% Finally, let's use the solve command.
solve('x^4-2^x = 0')
ans =
[ -4*lambertw(-1/4*log(2))/log(2)]
[ -4*lambertw(-1,-1/4*log(2))/log(2)]
[ -4*lambertw(-1/4*i*log(2))/log(2)]
[ -4*lambertw(1/4*log(2))/log(2)]
[ -4*lambertw(1/4*i*log(2))/log(2)]
% We have obtained a vector of 5 solutions, stated in terms of the logarithm
% function and the Lambert W function, a function used in advanced mathematics.
% We can get numerical values with the double command.
double(ans)
ans =
1.2396
16.0000
-0.1609+ 0.9591i
-0.8613
-0.1609- 0.9591i
% So, we have two complex solutions, plus the three real solutions found above.
echo off
diary off