% Exercise 1
% Find and plot where y=-x^2+5 crosses the line y=3
xx = -3:0.1:3;
yy = -xx.^2 + 5;  % element-wise for vector use
plot([-3 3],[3 3],'-.k', xx,yy,'r-'); 
pause
x0 = [-2 2];    % initial guesses for the roots

for n = 1:length(x0)
    x(n) = fzero('-x^2+5-3',x0(n));  % find where y=3
    y(n) = -x(n)^2 + 5;              % evaluate at that root
end

hold on
plot( [-3 3],[3 3],'-.k', xx,yy,'r-' )
% Display each roots on the plot
for n = 1:length(x)
    plot( x(n), y(n),'bo' );
    text( x(n)-0.5 , y(n)+0.5 , ...
        ['(' num2str(x(n),3) ',' num2str(y(n),1) ')' ] ); 
end
hold off