A simple question about solving the polynomial

조회 수: 3 (최근 30일)
Yu Wang
Yu Wang 2012년 3월 22일
This might be a very simple question to the programming gurus. any kind of help will be largely appreciated!!
x=[100 330 380 500 550];
y=[100 450 500 600 700];
p=polyfit(x,y,1); % first degree polynomial curve fitting
yFit=polyval(p,10); % return the value of y (named yFit) evaluated at 10 for example
My question is how can I returen the value of x evaluated at a value of y?

답변 (2개)

Geoff
Geoff 2012년 3월 22일
Well, there's two things here. Did you even want a polynomial in terms of x? If not, why not initially solve in terms of y?
Otherwise, if you want to express that single answer in terms of either y or x, remember that your vector 'p' contains the solved coefficients for a line:
y = Ax + B
So you tell us how you would find the value of x.
  댓글 수: 3
Geoff
Geoff 2012년 3월 23일
Well, I reminded you of the formula for a line. By calling polyfit() you found the values for A and B. That just leaves you to rearrange the equation for x.
John D'Errico
John D'Errico 2012년 3월 23일
You can't mean algebra? We have really big computers for that kind of stuff!

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


Walter Roberson
Walter Roberson 2012년 3월 23일
X_At_Particular_Y = interp1(y, x, The_Particular_Y, 'linear');
and conversely
Y_At_Particular_X = interp1(x, y, The_Particular_X, 'linear');
Warning: this formulation will only work if both x and y are strictly increasing or strictly decreasing.
If one of your variables is not strictly monotonic, then there are multiple locations for projecting that variable on to the other axis.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by