%% Roots in a Specific Interval
% Use the fzero function to find the roots of a polynomial in a specific interval. Among other uses, this method is suitable if you plot the polynomial and want to know the value of a particular root.
% For example, create a function handle to represent the polynomial 3x^7+4x^6+2x^5+4x^4+x^3+5x^2.

p = @(x) 3*x.^7 + 4*x.^6 + 2*x.^5 + 4*x.^4 + x.^3 + 5*x.^2;

%
% Plot the function over the interval [-2,1].

x = -2:0.1:1;
plot(x,p(x))
ylim([-100 50])
grid on
hold on

%
% From the plot, the polynomial has a trivial root at 0 and another near -1.5. Use fzero to calculate and plot the root that is near -1.5.

Z = fzero(p, -1.5)
plot(Z,p(Z),'r*')

% Copyright 2012 The MathWorks, Inc.