%% Find Asymptotes, Critical and Inflection Points
%% Define a Function 1

syms x
num = 3*x^2 + 6*x -1;
denom = x^2 + x - 3;
f = num/denom

%
%% Define a Function 2

fplot(f)

%
%% Find Asymptotes 1

roots = solve(denom)

%
%% Find Maximum and Minimum 1

f1 = diff(f);
crit_pts = solve(f1);

%
%% Find Maximum and Minimum 2

fplot(f)
hold on
plot(double(crit_pts), double(subs(f,crit_pts)),'ro')
title('Maximum and Minimum of f')
text(-4.8,5.5,'Local minimum')
text(-2,4,'Local maximum')
hold off

%
%% Find Inflection Point 1

f2 = diff(f1);
inflec_pt = solve(f2);
idx = imag(double(inflec_pt)) == 0;
inflec_pt = inflec_pt(idx);

%
%% Find Inflection Point 2

fplot(f, [-9 6])
hold on
plot(double(inflec_pt), double(subs(f,inflec_pt)),'ro')
title('Inflection Point of f')
text(-7,1,'Inflection point')
hold off