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

5 次查看(过去 30 天)
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
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