MATLAB: How to get the minima of a parabola

MATLABminimaparabolaSymbolic Math Toolbox

I have a function that starts with 2 matrices (7×1 in this case)
tol=input('enter tolerance matrix: ');
pix=input('enter pixel matrix: ');
plot(tol,pix);
syms x
a=polyfit(tol,pix,3);
b=poly2sym(a);
c=ezplot(diff(b,x),[0 100]);
"c" generates a parabola. I need to find the exact minima. Mainly the x value of the minima. How do i get it.
Thanks for the help

Best Answer

I don’t see why you need to use the Symbolic Math Toolbox for this. I suggest:
% Create data:
tol = linspace(1,10,7);
pix = polyval(poly([1 3 5]),tol) + 0.5.*(rand(1,7)-.5);
% Fit:
a = polyfit(tol,pix,3);
d1a = polyder(a); % First derivative
d2a = polyder(d1a); % Second derivative
ip = roots(d1a); % Inflection points
mm = polyval(d2a,ip); % Second derivative evealuated at inflection points
fprintf(1,'\n\tMinimum at %.3f\n', ip(mm>0))
fprintf(1,'\n\tMaximum at %.3f\n', ip(mm<0))
figure(1)
plot(tol, pix, '-b')
hold on
plot(ip, polyval(a,ip), '+r')
hold off
grid
If you get complex roots, this becomes more interesting to plot but the maths are the same.
Related Question