How to find the corresponding x value from a polynomial curve?

조회 수: 38 (최근 30일)
Guillermo Lopez
Guillermo Lopez 2012년 8월 30일
Hello everyone. I think my question is quite simple, but I can't figure out a way to do it. I've tried using interp1 but it hasn't worked for me as I have the y value and is the x value the one I need to find. My code is as follows: load('C:\Users\Weinberg\Desktop\Laboratorio de Bajas temperaturas\Electrostatic force microscopy\EFM pruebas\EFM_curve')
coefficient=polyfit(EFM_curve(1:256,1),EFM_curve(1:256,2),2);
minimum_value_x=min(EFM_curve(1:256,1));
maximum_value_x=max(EFM_curve(1:256,1));
x2=(minimum_value_x:0.01:maximum_value_x);
y2=polyval(coefficient,x2);
hold on
plot(EFM_curve(1:256,1),EFM_curve(1:256,2),'o')
plot(x2,y2,'r')
xlabel('Voltage');
ylabel('dF/dZ');
y2_max=max(y2)
Parabola_V=interp1(EFM_curve(1:256,1),y2_max)
grid on
I have a table with two columns of data, first column being the x values and the second column being the y values. I have found a polynomial curve (grade 2) which fits to my points nearly perfect. I then use in y2_max the max(y2) expression to find the y point where my curve is at it's maximum and I try to find the corresponding x value at that particular point of y. But using interp1 isn't doing it for me.
So the question: How would you obtain the exact x value when you have the maximum y value of your curve? Thanks in advance

답변 (3개)

Jürgen
Jürgen 2012년 8월 30일
interp1 is used to find an Yi-value for a known Xi value if you have a data zet (x,y)=> so it is not usefull to find the maximum, you have the values x2 corresponding with y2=> so if you know the index op max(y2) the corresponding x2 will be add the corresponding index, don't know for sure this is what you meant

Image Analyst
Image Analyst 2012년 8월 30일
You simply use the quadratic solution formula. You have the coefficients and you know it's a quadratic y = a1*x^2 + a2*x + a3 because you passed in 2 into polyfit(), so you use the formula you learned in 9th grade to solve for x given a specified y and the coefficients.
x = (-a2 + or - sqrt(a2^2 - 4 * a1 * (a3 - y))) / (2 * a1);
No need to use interp or polyval or anything like that.
  댓글 수: 1
Guillermo Lopez
Guillermo Lopez 2012년 8월 30일
Thanks a lot. I was trying to do something much much more difficult.

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


Star Strider
Star Strider 2012년 8월 30일
Since you already have a good fit to your polynomial, I suggest you determine the maxima and minima with:
dEFM_curve = polyder(coefficient);
xvals = roots(dEFM_curve);
xvals = xvals( (xvals >= minimum_value_x) & (xvals <= maximum_value_x) );
The vector of xvals should give you the x-coordinates of the maxima and minima of your fitted polynomial function. The second xvals statement was to be sure that you are only evaluating the roots that are within the range of x.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by