clear all;close all;

% Area under a graph Simple Example and plot it

% declare function and plot it
syms x
plot_range = [-10,10];

f = x^2;

%f= -x^2 + 100;
ezplot(f, plot_range);

hold on;

% define definite integral limits
int_limits =  [-6  6];

% Integrate

intf = int(f)  % Indefinite Integral

% Definite Integral via Indefinite result
int_val_ind = int(f,int_limits(1),int_limits(2))
 

% Idiot Check! Definite Integral via Indefinite result
subs(intf,int_limits(2)) - subs(intf,int_limits(1))
% not really a necessary bit of code as Def. Int is the way to do it!

% Set up plot
range = int_limits(1):0.1:int_limits(2);
y = subs(f,range); %sample values on curve

% Shade area below the curve
area(range,y, 'FaceColor',[0, 0, 1], 'LineStyle', 'none');

axis tight;
shg
