clear all; close all;


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


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

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

x=xmin:xstep:xmax; % Create some x values to evaluate f(x)

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

plot(x,y); % plot it

%%%  Plot X and Y axes and label

title('f(x) = x^4 -3x^3 + 2x^2 -2x +1')

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))

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



end;

shg; % Show Figure


