clc
clear vars
close all
%This clears all the other values that have previously been added and also
%clears all graphs that have been made as well
deg=input('please enter the degree of the polynomial ');
for n=1:deg+1
    coef(n)=input(['Please enter the coefficient of the value of x^',num2str(n-1) ': ']);
end
%Here the code is asking the user to enter the highest degree for the
%function 
P=0;
x=[-4:0.1:4];
for n=1:deg
    P=P+coef(n+1).*x.^n;
end
%Here the code is asking the user to enter the values for the coefficients
%of the x values in ascending order, up until it reaches the highest index
%entered by the user

plot(x, P)
%This plots the graph from all the coefficients that have been given by the
%user

for i=1:length(P)
    if P(i)==0
        disp (x(i));
    end
end
s=sign(P);
%This for loop takes all the x-values from the graph and asigns them a
%number (1, -1, or 0) depending on whether they are abov the y axis, below
%it, or on it 
title('Polynomial Graph', 'FontSize',16,'FontWeight','bold','Color','b');
%This shows the name, the fontsize, the fontweight and the colour of the
%title.
xlabel('X-Axis','FontSize',12,'FontWeight','bold','Color','r');
ylabel('Y-Axis','FontSize',12,'FontWeight','bold','Color','r');
%This shows the name, fontsize, fontweight and the colour of the axis
%label.
xticks(-5:1:5)
yticks(-1500:100:1500)
%This shows the distance between each tick on each of the axis, xticks
%representing the x axis and yticks representing the y axis
grid
%The grid shows the lines from the axis so the reader can clearly see when
%ertain points cross over at certain places
vs=sign(P);
k2=1;
k=1;
for i=1:length(vs)
    if vs(i)~=vs(i+1),AND vs(i)~=0,AND vs(i+1)~=0;
        LB(k)=i;
        HB(k)=i+1;
        k=k+1;
    end
    if vs(i)==0
        E(k2)=i;
        k2=k2+1;
    end
end
%This for loop is meant to take the previously assigned numbers and sort
%them to find the whereabouts of the roots (aka the numbers that were given
%1 and -1, -1 and 1, or just 0, which shows the change in sign, which means
%there is a root there).
R1=x(LB)+(x(HB)-x(LB))/2;
R2=x(E);
%Above here is meant to take the converted numbers and turn them back into
%the numbers, which are the  values of the roots.
RT=[R1,R2];
RT=Sort(RT);
%This is is meant ot rearrange the roots in ascending order 
ymin=min(P);
ymax=max(P);
xlim([R1-2,R3+2]);
ylim([ymin-2,ymax+2]);
%The xlim and ylim here are supposed to be dependant on the values of the
%roots that have been calculated (unfortunately they do not work), so that
%when the roots are given, the amount of the graph shown depends on the
%whereabouts of the roots, so it is meant to change with the values that
%the user inputs.
        




