%% Compare the integrals of an approximating function and the standard one
%  This script requires ExT6_2point3 to be run prior
%  Notice how the accuracy of the polynomial changes as the determinant changes

%% Define a vector of x-values and evaluate the polynomial s at these values 
x = [min(x_given):.001:max(x_given)];
x = 0:.01:1;
y = eval(s);

%% Compute the integral of the polynomial numerically
disp('The integral of the polynomial');
Integral_Approx = trapz(x,y) 
pause;

%% Compute the integral of the trig function numerically
% For T6
disp('The integral of the polynomial');
Integral_Exact = trapz(x,Given_f(x))
pause;
% For T7
%Integral_Exact = trapz(x,exp(x.^2))

%% Compute the difference between the two integrals
Defect = abs(Integral_Approx - Integral_Exact)/(abs(Integral_Exact))

%% Plot the two curves and the area under the curve
% Plot the poly in green 
% figure; hold on;
% 
% plot(x_given,y_given,'*b','MarkerSize',12);
% legend('Given Points') % create a legend
% 
% r = max(abs(x_given))+6; % How wide is the range of the plotting window
% xlim([-r,r]);
% title('Approximating Trig Integrals via Polynomials')
% plot(x,y,'og','MarkerSize',10)
% pause
% % Plot the sine curve in black
% plot(x,Given_f(x),'.k','MarkerSize',10)
% % For T7
% %plot(x,exp(x.^2));
% 
% %% Create a legend
% legend('Polynomial Approximation', 'Exact Function')

