Fitting Curve With an Inverse Which Fits a Polynomial

45 Ansichten (letzte 30 Tage)
Ephraim Bryski
Ephraim Bryski am 5 Okt. 2020
Kommentiert: Ameer Hamza am 5 Okt. 2020
Hi. I have 8 data points with x and y values. I would like to input new y values and interpolate x values.
I am able to input new x values and interpolate y values. I can fit the points with a sixth order polynomial for y vs. x which is valid in the range. However, I cannot fit a polynomial for x vs. y
One approach is to solve the polynomial for each y value; however, I have thousands of y values I want to interpolate for, so it would be extremely computationally intensive.
Does anyone know a faster approach? Thanks!

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 5 Okt. 2020
Bearbeitet: Ameer Hamza am 5 Okt. 2020
The inverse of a polynomial is not a polynomial, so you cannot simply interpolate the inverse function. Following shows two approaches
1) fzero()
x = linspace(0, 2, 8);
y = 5*x.^6 + 3*x.^5; % y varies from 0 to 416.
pf = polyfit(x, y, 6);
y_pred = @(x) polyval(pf, x);
% find x, when y = 100;
y_val = 100;
x_val = fzero(@(x) y_pred(x)-y_val, rand);
2) Polynomial root finding. This method gives all possible solutions
x = linspace(0, 2, 8);
y = 5*x.^6 + 3*x.^5; % y varies from 0 to 416.
pf = polyfit(x, y, 6);
% find x, when y = 100;
y_val = 100;
pf(end) = pf(end)-y_val;
x_vals = roots(pf);
x_vals = x_vals(imag(x_vals)==0); % if you only want real roots.
  2 Kommentare
Ephraim Bryski
Ephraim Bryski am 5 Okt. 2020
I used the fzero() approach; it works perfectly and is much faster than solve(). Thank you!
Ameer Hamza
Ameer Hamza am 5 Okt. 2020
I am glad to be of help!
Yes, symbolic mathematics is much slower as compared to numerical equivalent.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Polynomials finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by