%% Problem 5

%% Plotting x^8 and 4^x together
% We first look at the graphs in the interval [-5,5]:
ezplot('x^8',[-5,5]); hold on
ezplot('4^x',[-5,5]); hold off

%% Now we look at interval [-1.5, 1.5]
% There seem to be two intersection points, 
% near -.8 and near 1.2
ezplot('x^8',[-1.5,1.5]); hold on
ezplot('4^x',[-1.5,1.5]); hold off

%% Finding two intersection points with fzero
% We use fzero with the difference of the two functions:
format long g               % show all digits of results
x1 = fzero('x^8-4^x',-.8)   % find solution near -.8
x2 = fzero('x^8-4^x',1.2)   % find solution near 1.2

ezplot('x^8',[-1.5,1.5]); hold on
ezplot('4^x',[-1.5,1.5]); 
plot(x1,x1^8,'ro',x2,x2^8,'ro'); % mark intersection points with red "o"
hold off  

%% Using solve to find solutions
% solve returns a vector with all solutions in symbolic form (in terms of
% some strange lambertw function).
% Using double(s) shows the numerical value.
% The solve command finds 3 real solutions and 6 complex solutions
s = solve('x^8-4^x')
double(s)

%% Finding the third intersection point with fzero
% It seems that we missed the intersection point at x=16 before.
% We draw the graphs again on a larger interval.
% Then we use fzero to find a solution near x=15
ezplot('x^8',[0,20]); hold on
ezplot('4^x',[-0,20]);
x3 = fzero('x^8-4^x',15)  % find solution near 15
plot(x3,x3^8,'ro')        % mark intersection point with red "o"

