How to find interpolating polynomial
조회 수: 20 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Walter Roberson
2013년 10월 21일
interpolate() is not the correct function to extract an interpolating polynomial. See polyfit() and polyval() and linspace().
댓글 수: 2
Maciej Rzymek
2020년 10월 26일
polyfit won't give you interpolation, but approximation which is way different. He should use interp1.
John D'Errico
2020년 10월 26일
@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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!