How to find interpolating polynomial
22 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to find the interpolating polynomial of degree 20 for the function f(x)=(x^2+1)^-1 using 21 equally spaced nodes on the interval [-5,5]. The syntax matlab says to use is
But I only know the amount of nodes, function, and the interval. Thanks for any help!
0 commentaires
Réponses (1)
Walter Roberson
le 21 Oct 2013
interpolate() is not the correct function to extract an interpolating polynomial. See polyfit() and polyval() and linspace().
2 commentaires
Maciej Rzymek
le 26 Oct 2020
polyfit won't give you interpolation, but approximation which is way different. He should use interp1.
John D'Errico
le 26 Oct 2020
@Maciej Rzymek - actually, you are incorrect, on several counts. Hard to do in such a short space. :)
- polyfit CAN produce an interpolating polynomial, if you choose the proper order polynomial. Thus with n data points, set the order to be n-1. This will produce a polynomial with n coefficients to estimate, and therefore, an interpolating polynomial.
- Since the goal was to produce an interpolating polynomial, interp1 will NOT satisfy that goal.
In fact, this problem is a classical one, chosen to show how poorly an interpolating polynomial can react. That particular function is one that will generate a wildly oscillatory polynomial, with immense swings between the points. You may wish to read about Runge's phenomenon.
The one thing I agree with what you said is that if your goal is purely to interpolate such a function, and to do it well, then there are far better tools than a polynomial. For example, interp1 in this case by use of pchip as the interpolant, will produce a well behaved, non-oscillatory result.
But if the goal is to satisfy the requirements of a homework assignment, then you have no choice.
Voir également
Catégories
En savoir plus sur Polynomials 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!