clc;
clear;
close all;

x = chebfun('x', [-1.1 2]);
f = (x.^2 - x - 1).*x;
df = diff(f);
d2f = diff(df);

r = roots(f);
e = roots(df);

maxima = e(d2f(e) < 0);
minima = e(d2f(e) > 0);

figure;

subplot(1,3,1);
plot(f);
hold on;
plot(r, f(r), 'ko');
plot(maxima, f(maxima), 'r.', 'MarkerSize', 20);
plot(minima, f(minima), 'b.', 'MarkerSize', 20);
grid on;

subplot(1,3,2);
plot(df);
hold on;
plot(e, df(e), 'ko');
grid on;

subplot(1,3,3);
plot(d2f);
hold on;
plot(e, d2f(e), 'ko');
grid on;
