Extreme is at x = 6.00
Second derivative value on extreme = 2.00.
It is > 0, so it is a minimum point.
It uses derivative, which is represented in b as obtained using b = polyder(a);.
The function fzero is used again for for $q(x)$ instead for $p(x)$.
The additional code is as follow.
% create symbolic function for q(x)qs = poly2sym(b);
% create numerical function from stringfqx = inline(qs);
% find rootextreme = fzero(fqx, 0);
% get next derivativec = polyder(b);
% create symbolic functio for r(x)rs = poly2sym(c);
% check value of extreme derivativeved = polyval(c, extreme);
fprintf('Extreme is at x = %.2f\n', extreme);
% show analysisfprintf(['Second derivative value on extreme'...' = %.2f.\n'], ved);
if ved >0 fprintf('It is > 0, so it is a minimum point.')
elseif ved <0 fprintf('It is < 0, so it is a maximum point.')
else fprintf('It is = 0, so it is an inflection point.')
end
>> function_extreme_points_max
p(x) = 12*x - x^2 - 32
root-1 = 4.00
root-2 = 8.00
Extreme is at x = 6.00
Second derivative value on extreme = -2.00.
It is < 0, so it is a maximum point.
Plot of $p(x)$ and $q(x)$ is given below.
Full lines of code are as follow.
% function_extreme_points_min% clear previous statesclear;
% define range of xxbeg = 0;
xend = 10;
% define a polynomial via its coefficientsa = [-112-32];
% create data for ploting (x, px)x = [];
px = [];
for i = xbeg:xend
x = [x i];
px = [px polyval(a, i)];
end% calculate derivativeb = polyder(a);
% create data for ploting (x, qx)x = [];
qx = [];
for i = xbeg:xend
x = [x i];
qx = [qx polyval(b, i)];
end% plot functions px and qxplot(x, px, 'rs-', x, qx, 'bo-');
xlim([xbeg xend]);
legend('p(x)', 'q(x)', ...'location', 'northeast');
xlabel('x');
ylabel('y');
grid on;
%{%}% create symbolic function p(x)ps = poly2sym(a);
% create function from stringfpx = inline(ps);
% find rootsroot1 = fzero(fpx, 0);
root2 = fzero(fpx, 10);
% show resultsfprintf("p(x) = %s\n", ps);fprintf("root-1 = %.2f\n", root1);fprintf("root-2 = %.2f\n", root2);%}% create symbolic function for q(x)qs = poly2sym(b);
% create numerical function from stringfqx = inline(qs);
% find rootextreme = fzero(fqx, 0);
% get next derivativec = polyder(b);
% create symbolic functio for r(x)rs = poly2sym(c);
% check value of extreme derivativeved = polyval(c, extreme);
fprintf('Extreme is at x = %.2f\n', extreme);
% show analysisfprintf(['Second derivative value on extreme'...' = %.2f.\n'], ved);
if ved >0 fprintf('It is > 0, so it is a minimum point.')
elseif ved <0 fprintf('It is < 0, so it is a maximum point.')
else fprintf('It is = 0, so it is an inflection point.')
end