close all
f = @(x) 2*x.^2+2*x-3;
a = -3;
b = -1;

x = [a:0.01:b];
figure(1)
hold off
plot(x, f(x), 'k', 'LineWidth', 2);
hold on
plot(a, 0, 'ro', 'Markersize', 8, 'MarkerFaceColor', 'b')
text(a+0.1, 0, 'a', 'FontSize', 12);
plot(a, f(a), 'ro', 'Markersize', 8, 'MarkerFaceColor', 'b')
text(a+0.1, f(a), '[a, f(a)]', 'FontSize', 12);
line([a,a], [0,f(a)], 'Color', 'b', 'LineStyle', '-.', 'LineWidth', 2)

plot(b, 0, 'ro', 'Markersize', 8, 'MarkerFaceColor', 'r')
text(b+0.05, 0, 'b', 'FontSize', 12);
plot(b, f(b), 'ro', 'Markersize', 8, 'MarkerFaceColor', 'r')
text(b-0.25, f(b)-0.25, '[b, f(b)]', 'FontSize', 12);
line([b,b], [0,f(b)], 'Color', 'r', 'LineStyle', '-.', 'LineWidth', 2)

y = (f(b)-f(a))*(x-a)/(b-a)+f(a);
plot(x, y, 'g', 'LineWidth', 2);

grid on
c = a-f(a)*(b-a)/(f(b)-f(a));

plot(c, 0, 'ro', 'Markersize', 8, 'MarkerFaceColor', 'g')
text(c+0.1, 0, 'c', 'FontSize', 12);
line([c,c], [0,f(c)], 'Color', 'r', 'LineStyle', '-.', 'LineWidth', 2)

figure(2)
plot(x, f(x), 'k', 'LineWidth', 2);
hold on
plot(a, 0, 'ro', 'Markersize', 8, 'MarkerFaceColor', 'b')
text(a+0.1, 0, 'a', 'FontSize', 12);
plot(a, f(a), 'ro', 'Markersize', 8, 'MarkerFaceColor', 'r')
line([a,a], [0,f(a)], 'Color', 'b', 'LineStyle', '-.', 'LineWidth', 2)

plot(b, 0, 'ro', 'Markersize', 8, 'MarkerFaceColor', 'r')
text(b+0.05, 0, 'b', 'FontSize', 12);
plot(b, f(b), 'ro', 'Markersize', 8, 'MarkerFaceColor', 'r')
line([b,b], [0,f(b)], 'Color', 'r', 'LineStyle', '-.', 'LineWidth', 2)

m =(a+b)/2;
plot(m, 0, 'ro', 'Markersize', 8, 'MarkerFaceColor', 'b')
text(m+0.05, 0, 'm', 'FontSize', 12);
plot(m, f(m), 'ro', 'Markersize', 8, 'MarkerFaceColor', 'b')
line([m,m], [0,f(m)], 'Color', 'b', 'LineStyle', '-.', 'LineWidth', 2)
grid on
