Presentation is loading. Please wait.

Presentation is loading. Please wait.

Interpolation Methods

Similar presentations


Presentation on theme: "Interpolation Methods"— Presentation transcript:

1 Interpolation Methods
Fish 559; Lecture 21 a

2 What is Interpolation? There is a function f(x) that is very “expensive” (or difficult) to evaluate. We wish to compute f(x) for many values of x as “cheaply” as possible. We have data points (x,y=g(x)) but do not know the function g. We wish to compute g(x) for values of x other than those for which the data points are available.

3 Consider the “Runge” Function
Given these seven data points, how do we determine the values of y for other values for x?

4 Linear Interpolation-I
Approximate f(x) between xi and xi+1 by a straight line connecting xi and xi+1, i.e.: or

5 Linear Interpolation-II
Linear interpolation is very accurate in this case, but it requires knowing between which values of xi the x we are interested in lies

6 Linear Interpolation-III
R includes the function approx which can be used to perform linear interpolation: approx(x, y, xout) x,y – the vector of (x,y) pairs on which to base the calculations. xout – a vector of values of x for which values of g(x) are required.

7 Polynomial Interpolation-I
There are many ways to approximate a function using a polynomial. The simplest is to approximate the function by: Note that: this approximation is exact for x=x1, x2, x3, etc.; and a single equation is used to approximate the entire function.

8 Polynomial Interpolation-II
The polynomial passes though all seven points but….

9 Polynomial Interpolation-III
A better approximation can be obtained in this case by applying polynomial interpolation with N=3 (i.e. quadratic functions)

10 Rational Interpolation-I
Rather than approximating a function by a simple polynomial, we can approximate it by the ratio of polynomials, i.e.: This approach can deal with poles in the function to be approximated (unfortunately even when they are not there).

11 Rational Interpolation-II
Rational approximation performs better than simple polynomial interpolation for the Runge function (as expected?)

12 More Examples

13 Splines-I Cubic splines are piecewise cubic polynomials that approximate a function such that: The zeroth, first and second derivatives are continuous; the approximating function matches the points on which it is based; and the second derivatives of the approximating function match the second derivatives of the function.

14 Splines II Define a set of points (called “knots”) – these are the points for which data are available: The cubic spline is defined by the equation: This equation has four parameters for each pair of knots. The values for these parameters are defined from the function values at the knots and the (numerical) second derivatives at the knots.

15 Splines III The cubic spline is able to satisfactorily mimic the
underlying shape almost perfectly y3 <- spline(x,y) lines(y3,col=19,lwd=3)

16 Splines -IV Using a Spline for interpolation requires that the values for the parameters be computed. In order to predict the value of y for some x, it is necessary to apply a search algorithm (e.g. bisection) to find the knots between which x lies.

17 spline(x, y, n, periodic, xmin, xmax )
Splines V R includes the function spline: spline(x, y, n, periodic, xmin, xmax ) Arguments: x, y – the data (required); n – number of output points; periodic – is the function periodic? xmin / xmax – range to predict over. Output: List with components x and y that provide the results of the cubic spline fitting.

18 Spline vs linear interpolation based on 8, 12 and 16 points
Splines VI Spline vs linear interpolation based on 8, 12 and 16 points

19 Interpolation and Extrapolation-I
Polynomial and rational approximation are methods for interpolation. In principle, they can be used to extrapolate beyond the range of the xs for which data are available. This should, however, be done with considerable caution. Consider the following selectivity ogive.

20 Interpolation and Extrapolation-II
3-point polynomial interpolation. Extrapolation beyond age=0 and age=25 is based on the results for the first and last intervals


Download ppt "Interpolation Methods"

Similar presentations


Ads by Google