필터 지우기
필터 지우기

how to solve a fourth degree polynomial for x / polyval for x

조회 수: 5 (최근 30일)
Kenneth Carlson
Kenneth Carlson 2020년 9월 25일
댓글: Steven Lord 2020년 9월 28일
I've designed an app that is able to extrapolate the y at any given x. To do this i've used polyfit to generate a fourth degree polynomial, based on testdata. It works perfectly to find y when x is given.
Now i would like to reverse it so that I can enter a y, and get the x-value for the same polynomial. Doesn't MatLab have a built-in function for this?
Below is shown the code I've used to generate the polynomial and find the y-value
y_sample=[18.5610 21.298 27.531 36.8 51.221]; % test data
x_sample = (0.25:0.25:1.25); % x-values for test data
p = polyfit(x_sample,y_sample,4); % fourth degree polynomial
y_value = polyval(p,X) % THIS IS THE LINE I WISH TO BE SOLVED FOR X
I know 4th degree isn't optimal for this example, but it is needed for some of the other uses of the function.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 9월 25일
편집: Ameer Hamza 2020년 9월 25일
What about reversing the interpolation
y_sample=[18.5610 21.298 27.531 36.8 51.221]; % test data
x_sample = (0.25:0.25:1.25); % x-values for test data
p = polyfit(y_sample,x_sample,4); % fourth degree polynomial
x_value = polyval(p,Y)
  댓글 수: 4
Kenneth Carlson
Kenneth Carlson 2020년 9월 28일
Unfortunately it requires the optimization toolbox, which I don't have avalible. I will have to settle for the "not as precise" result, and see how it works out for now.
Thanks again though.
Steven Lord
Steven Lord 2020년 9월 28일
Since you're trying to find a zero of one equation in one unknown you don't actually need fsolve here. fzero is in MATLAB and can handle this problem.

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

추가 답변 (1개)

Mohlouwa Joseph BOTMAN
Mohlouwa Joseph BOTMAN 2020년 9월 28일
Consider the two polynomials 3 2 p(s) = s + 4s +5s + 2 and q(s) = s +C
1.1 Determine p(s)q(s) based on the simulation software.
(3)
1.2 Determine the poles and zeros of
( )
( )
( )
q s
G s
p s
= based on the simulation software
  댓글 수: 1
Steven Lord
Steven Lord 2020년 9월 28일
Since this is not related to the original question, you should post this as a separate question. When you do, since this sounds like a homework assignment please show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.

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

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by