How to find interpolating polynomial
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Walter Roberson
el 21 de Oct. de 2013
interpolate() is not the correct function to extract an interpolating polynomial. See polyfit() and polyval() and linspace().
2 comentarios
Maciej Rzymek
el 26 de Oct. de 2020
polyfit won't give you interpolation, but approximation which is way different. He should use interp1.
John D'Errico
el 26 de Oct. de 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.
Ver también
Categorías
Más información sobre Polynomials en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!