Python:Polynomial Interpolation vs. Fit

From PrattWiki
Revision as of 16:30, 23 April 2020 by DukeEgr93 (talk | contribs) (Created page with "== Introduction == Polynomial interpolation is different from polynomial fitting. Polynomial fitting seeks to take a single polynomial - generally of a low order - and finds...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

Polynomial interpolation is different from polynomial fitting. Polynomial fitting seeks to take a single polynomial - generally of a low order - and finds the coefficients which gets the polynomial collectively as close to all the points as possible, but which may not actually hit any of the points.

Polynomial interpolation will always be of an order one less than the number of points used; it will always go through the basis points you use to create the interpolation. You will use np.polyfit with the order of the fit being one less than the number of points to get the coefficients for the polynomial and then np.polyval with those coefficients to predict values. There is no mechanism in interp1d to do polynomial fitting.

Note that linear interpolation essentially takes every two points and calculates the straight line between them. The algorithm successively applies polynomial interpolation to each pair of points.

Example

The code and graph below will show the differences between the code for and meaning of linear interpolation, first order fitting, and polynomial interpolation. In this case, the goal is to estimate values of the underlying function at two different independent locations - one at x=1.5 and one at x=6.