%****** CLEAN MATLAB ENVIRONMENT ******

clc % to clear the command window 
clear all % to clear the workspace 

degree = input("Enter the degree of the polynomial: ") % the input function allows to define the degree of the polynomial

%****** FOR LOOP ******

for i = 0:(degree)
    co_x = input("Enter the coefficients of x: ") % the input function allows to define the coefficients of x 
    a(:,i+1) = co_x
end

px = [-100:1:100]; % x values range from -100 to 100 (x axis)

ps = 0; % y axis stars with 0 + the first y value

%****** FOR LOOP ******

for i = 0:(degree) % 0 to chosen degree
    k = degree-i; % x is to the power of k (chosen degree -1 each time)
    p = a(i+1)*px.^k; % polynomial equation (coefficient times x to the power of k)
    ps = ps+p; % y axis (0 + p)
end

%****** PLOT THE GRAPH ******

plot (px,ps,'b') % plotting x(px) and y(ps) values in blue

grid on % shows grid on graph
grid minor % shows grid on graph

title ('\color{blue} Graph of Polynomial', 'FontWeight', 'bold', 'FontSize', 16) % title colour, name, weight and size
xlabel ('\color{red} x-axis', 'FontWeight', 'bold', 'FontSize', 12) % label colour, name, weight and size
ylabel ('\color{red} y-axis', 'FontWeight', 'bold', 'FontSize', 12) % label colour, name, weight and size

%****** FINDING REAL ROOTS******

if p>0 % if y is more than 0 then there are 2 real roots
    disp('There are two real roots')
elseif p==0 % if y is 0 then there is 1 real root 
    disp('There is one real root')
else % if y is less than 0 then there are no real roots
    disp('There are no real roots')
end
