How to find interpolating polynomial

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
interpolate(nodes, values, ind, F)
But I only know the amount of nodes, function, and the interval. Thanks for any help!

回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 10 月 21 日

0 投票

interpolate() is not the correct function to extract an interpolating polynomial. See polyfit() and polyval() and linspace().

2 件のコメント

Maciej Rzymek
Maciej Rzymek 2020 年 10 月 26 日
polyfit won't give you interpolation, but approximation which is way different. He should use interp1.
John D'Errico
John D'Errico 2020 年 10 月 26 日
@Maciej Rzymek - actually, you are incorrect, on several counts. Hard to do in such a short space. :)
  1. 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.
  2. 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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangePolynomials についてさらに検索

タグ

質問済み:

2013 年 10 月 21 日

コメント済み:

2020 年 10 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by