clc
clearvars
close all

dg=input('Enter the degrees of the Polynomial; ');
% asks user to input variables of the equation which is imputed to the for
% stament
% start value for loop
for i=1:dg+1
    c(i)=input(['enter coefficint multiplying x^' num2str(i-1) ': ']);
%     repeats each X variants given in polymonial starting at 0 power each
%     time plus 1 to the power.

end  
x=[-100:0.1:100];
% sets range for X
p=0;
ps = 0
% initialising start values of the simulation
for i=0:dg
    p= c(i+1)*x.^i;
    ps = ps + p
%     for loop calulating each vaule given on polynomial and coeffient
%     inputs. this is repeated to calulate each value along a y axis to
%     give values that can be repusiented fully. uses the matrix as 0.1
%     steps between -100 amd 100.
end
plot(x,ps,'color',[0,0,1]);
% plots graps
ylim([-30,50]);
xlim([-6,8]);
% sets limits of the values of y and x ploted on graph
xlabel('X-axis','color',[0,0,1]);
ylabel('Y-axis');
% lables axis
xline(0);
yline(0);
% plots origin lines of y=0, X=0

bisect = sign(ps)
% creates array of values for the change in sign for Y values
ro = find([0 diff(bisect)]~=0);
% locates sign changes in bisect array
roots = ps(ro);
% finds x values when sign changes in Y from roots
sr = (roots);
% rearranges roots into increaseing order
numroots = numel(roots);
%assigns value for number of roots
if numroots>0
%     if statments for when there is real roots
    disp("There are");
    disp(numroots)
    disp("real roots that lie on interval [-100:100].");
    disp("these are X=");
    disp(sr);
%     displaying previosly caculated values when there are roots
else
    disp("There are no real roots to be found on interval [-100:100]");
%     displays message for when there isn't any real roots

end
% end

