how to solve a fourth degree polynomial for x / polyval for x
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kenneth Carlson
le 25 Sep 2020
Commenté : Steven Lord
le 28 Sep 2020
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.
0 commentaires
Réponse acceptée
Ameer Hamza
le 25 Sep 2020
Modifié(e) : Ameer Hamza
le 25 Sep 2020
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 commentaires
Steven Lord
le 28 Sep 2020
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.
Plus de réponses (1)
Mohlouwa Joseph BOTMAN
le 28 Sep 2020
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 commentaire
Steven Lord
le 28 Sep 2020
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.
Voir également
Catégories
En savoir plus sur Spline Postprocessing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!