x = linspace(-2, 2, 500);
y = x .^ 2 + 2;
plot(x, y, 'b-', 'LineWidth', 2);
grid on;
fontSize = 20;
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
ylim([0, 7]);
xTangent = -1;
slope = 2 * xTangent;
yTangent = xTangent .^ 2 + 2;
hold on;
plot(xTangent, yTangent, 'r*', 'LineWidth', 2, 'MarkerSize', 10);
yTangentLine = slope * (x - xTangent) + yTangent;
plot(x, yTangentLine, 'b-', 'LineWidth', 2);
Best Answer