clc                 %Clear command window
clear all           %Clear workspace
close all           %Close open tabs ie.m from previous graphs

d=input('Enter the degree of your polynomial: ');    %Ask user to input the polynomial's degree, allocating to d
for n=1:d+1         %Using n as loop counter, generate n values from one to one more than the value of d
    coef(n)=input(['Enter the coefficient of x^',num2str(n-1),': ']);    %Ask user to input the coefficient of each power of x, using loop counter n
end

x=-100:0.1:100;     %Generate range of x values at 0.1 intervals, from -100 to 100
y=0;                %Introduce y to workspace ready for next for loop
for i=0:d           %Using i as loop counter, generate i values from 0 to the value of d
    y=y+coef(i+1).*x.^i;      %Calculate y values for corresponding x values
end                 
y;                  %Bring y values together
P=y;                %Allocate in vector P

plot(x,P,'color',[0,0,1])     %Plot graph of polynomial in blue
title('Graph of Polynomial','color',[0,0,1],'FontSize',16,'FontWeight','bold');  %Display and format graph title
xlabel('x-axis','color',[1,0,0],'FontSize',12,'FontWeight','bold');              %Display and format x-axis
ylabel('y-axis','color',[1,0,0],'FontSize',12,'FontWeight','bold');              %Display and format y-axis
grid on;            %Display major gridlines
grid minor;         %Display minor gridlines