clear all; close all;

p = [3, 1, 2]; % Create a polynomial f(x) = 3x^2 + x + 2


% Create some x values to evaluate f(x)
xmin = -5.0;
xmax = 5.0;
xstep = 0.2;

yoffset = 0.0; % extend axes beoynd range of y for plot

x=xmin:xstep:xmax;  % Make x


y = polyval(p,x); %evaluate polynomial

plot(x,y); % plot it


%%%  Plot X and Y axes and label

title('f(x) = 3x^2 + x + 2')

hold on
plot([xmin xmax],[0 0],'-k'); % X Axis
plot([0 0],[min(y)-yoffset max(y)+yoffset],'-k'); % Y Axis


axis tight % force concise display of plot


roots_p = roots(p)  % Solve the Equation  


% Plot Roots

% In general roots of polynomial may be comlex.
hold on;

[n m] = size(roots_p); % n = how many roots

for i = 1:n

    if isreal(roots_p(i)) % NOTE in this case no REAL roots

        plot(roots_p(i),0,'o','LineWidth',2,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','r',...
                'MarkerSize',10);
    end;



end;

shg; % Show Figure

