필터 지우기
필터 지우기

How do I get the minima of a parabola?

조회 수: 7 (최근 30일)
jchris14
jchris14 2014년 4월 17일
댓글: jchris14 2014년 4월 17일
I have a function that starts with 2 matrices (7x1 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

채택된 답변

Star Strider
Star Strider 2014년 4월 17일
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.
  댓글 수: 5
Star Strider
Star Strider 2014년 4월 17일
John — Noted. In his code, jchris14 mentions fitting a 3-degree polynomial with polyfit. Reading between the lines...
jchris14
jchris14 2014년 4월 17일
John- sorry, i meant turning point not inflection point. I dont really have any use for the inflection point of the 3-degree polynomial.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jos (10584)
Jos (10584) 2014년 4월 17일
Why not solve this analytically?
P = polyfit(x,y,2) % fit parabola
% vertex is a minimum when P(1) > 0, a maximum when P(1) < 0
% (no vertex for a straight line when P(1)=0 !)
h = -P(2) / (2*P(1)) % x value of the minima (maxima)
k = P(3)-((P(2)^2) / (4*P(1))) % y value of the minima (maxima)
% polyval(P,h) will give the same value!
%(h,k) is the vertex point
% y = (p(1)*(x-h)^2) + k % vertex notation
  댓글 수: 2
Star Strider
Star Strider 2014년 4월 17일
In his code, jchris14 is using polyfit to fit a 3-degree polynomial, not actually a parabola. Otherwise I agree. He also wants to do this using MATLAB functions, and I’m not going to discourage that.
jchris14
jchris14 2014년 4월 17일
Jos- thanks for the tip. I was thinking about doing it this way but using the command "roots" simplified the whole sequence of commands and shortened the whole code to just 4 or 5 lines.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by