clear all;close all;

% Area under a graph Simple Example and plot it

% declare function
syms x
plot_range = [-5,5];

f = x^3;


int_limits =  [-3,3];



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

% WRONG (for Area)!  Answer is ZERO
% For x^3 need to split at x = 0
% Exercise: Write a general function to work this point out.

% Do Area Properly
int_area = abs(int(f,int_limits(1),0)) + abs(int(f,0,int_limits(2)))

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

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

range = 0: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');

%plot function
hf =ezplot(f, plot_range);

set(hf,'Color','black');



% Find max min values over curves for plot axes
range = plot_range(1):0.1:plot_range(2);
y = subs(f,range); %sample values on curve f1

miny = min(y); %for plot y-axis
maxy = max(y);



plot(plot_range,[0 0], 'k'); % x-axis

plot([0 0],[miny maxy], 'k'); % y-axis


axis tight;
shg
