MATH1070 3 Interpolation

  • Upload
    jigarso

  • View
    225

  • Download
    0

Embed Size (px)

Citation preview

  • 7/29/2019 MATH1070 3 Interpolation

    1/56

    > 4. Interpolation and Approximation

    Most functions cannot be evaluated exactly:

    x, ex, ln x, trigonometric functions

    since by using a computer we are limited to the use of elementary

    arithmetic operations+,,,

    With these operations we can only evaluate polynomials and rationalfunctions (polynomial divided by polynomials).

    4. Interpolation Math 1070

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    2/56

    > 4. Interpolation and Approximation

    Interpolation

    Given pointsx0, x1, . . . , xn

    and corresponding values

    y0, y1, . . . , yn

    find a function f(x) such that

    f(xi) = yi, i = 0, . . . , n .

    The interpolation function f is usually taken from a restricted class offunctions: polynomials.

    4. Interpolation Math 1070

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    3/56

    > 4. Interpolation and Approximation > 4.1 Polynomial Interpolation Theory

    Interpolation of functions

    f(x)

    x0, x1, . . . , xn

    f(x0), f(x1), . . . , f (xn)

    Find a polynomial (or other special function) such that

    p(xi) = f(xi), i = 0, . . . , n .

    What is the error f(x) = p(x)?

    4. Interpolation Math 1070

    http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    4/56

    > 4. Interpolation and Approximation > 4.1.1 Linear interpolation

    Linear interpolation

    Given two sets of points (x0, y0) and (x1, y1) with x0 = x1, draw a linethrough them, i.e., the graph of the linear polynomial

    x0 x1y0 y1

    (x) =x x1

    x0 x1 y0 +x x0

    x1 x0 y1

    (x) =(x1 x)y0 + (x x0)y1

    x1 x0(5.1)

    We say that (x) interpolates the value yi at the point xi, i = 0, 1, or(xi) = yi, i = 0, 1

    Figure: Linear interpolation4. Interpolation Math 1070

    4 I l i d A i i 4 1 1 Li i l i

    http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    5/56

    > 4. Interpolation and Approximation > 4.1.1 Linear interpolation

    Example

    Let the data points be (1, 1) and (4,2). The polynomial P1(x) is given by

    P1(x) =

    (4

    x)

    1 + (x

    1)

    2

    3 (5.2)

    The graph y = P1(x) and y =

    x, from which the data points were taken.

    Figure: y =

    x and its linear interpolating polynomial (5.2)4. Interpolation Math 1070

    > 4 I t l ti d A i ti > 4 1 1 Li i t l ti

    http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    6/56

    > 4. Interpolation and Approximation > 4.1.1 Linear interpolation

    Example

    Obtain an estimate of e0.826 using the function values

    e0.82 = 2.270500, e0.83 = 2.293319

    Denote x0 = 0.82, x1 = 0.83. The interpolating polynomial P1(x)interpolating ex at x0 and x1 is

    P1(x) = (0.83 x) 2.270500 + (x 0.82) 2.2933190.01

    (5.3)

    andP1(0.826) = 2.2841914

    while the true value s

    e0.826

    = 2.2841638

    to eight significant digits.

    4. Interpolation Math 1070

    > 4 Interpolation and Approximation > 4 1 2 Quadratic Interpolation

    http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    7/56

    > 4. Interpolation and Approximation > 4.1.2 Quadratic Interpolation

    Assume three data points (x0, y0), (x1, y1), (x2, y2), with x0, x1, x2 distinct.We construct the quadratic polynomial passing through these points usingLagranges folmula

    P2(x) = y0L0(x) + y1L1(x) + y2L2(x) (5.4)with Lagrange interpolation basis functions for quadratic interpolatingpolynomial

    L0(x) =(xx1)(xx2)(x0x1)(x0x2)

    L1(x) =

    (x

    x0)(x

    x2)

    (x1x0)(x1x2)

    L2(x) =(xx0)(xx1)(x2x0)(x2x1)

    (5.5)

    Each Li(x) has degree 2 P2(x) has degree 2. MoreoverLi(xj) = 0, j = iLi(xi) = 1

    for 0

    i, j

    2 i.e., Li(xj) = i,j =

    1, i = j

    0, i = jthe Kronecker delta function.

    P2(x) interpolates the data

    P2(x) = yi, i=0,1,2

    4. Interpolation Math 1070

    > 4 Interpolation and Approximation > 4 1 2 Quadratic Interpolation

    http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    8/56

    > 4. Interpolation and Approximation > 4.1.2 Quadratic Interpolation

    Example

    Construct P2(x) for the data points (0,1), (1,1), (2, 7). Then

    P2(x) =

    (x

    1)(x

    2)

    2 (1)+x(x

    2)

    1 (1)+x(x

    1)

    2 7 (5.6)

    Figure: The quadratic interpolating polynomial (5.6)

    4. Interpolation Math 1070

    > 4 Interpolation and Approximation > 4 1 2 Quadratic Interpolation

    http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    9/56

    > 4. Interpolation and Approximation > 4.1.2 Quadratic Interpolation

    With linear interpolation: obvious that there is only one straight linepassing through two given data points.With three data points: only one quadratic interpolating polynomialwhose graph passes through the points.Indeed: assume Q2(x), deg(Q2) 2 passing through(xi, yi), i = 0, 1, 2, then it is equal to P2(x). The polynomial

    R(x) = P2(x)Q2(x)

    has deg(R) 2 and

    R(xi) = P2(xi)

    Q2(xi) = yi

    yi = 0, for i = 0, 1, 2

    So R(x) is a polynomial of degree 2 with three roots R(x) 0

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.1.2 Quadratic Interpolation

    http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    10/56

    > 4. Interpolation and Approximation > 4.1.2 Quadratic Interpolation

    ExampleCalculate a quadratic interpolate to e0.826 from the function values

    e0.82

    = 2.27050 e0.83

    = 2.293319 e0.84

    = 2.231637

    With x0 = e0.82

    , x1 = e0.83

    , x2 = e0.84

    , we have

    P2(0.826)

    = 2.2841639

    to eight digits, while the true answer e0.826

    = 2.2841638 and

    P1(0.826)

    = 2.2841914.

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.1.3 Higher-degree interpolation

    http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    11/56

    > p pp > g g p

    Lagranges Formula

    Given n + 1 data points (x0, y0), (x1, y1), . . . , (xn, yn) with all xisdistinct, unique Pn, deg(Pn) n such that

    Pn(xi) = yi, i = 0, . . . , ngiven by Lagranges Formula

    Pn(x) =n

    i=0

    yiLi(x) = y0L0(x) + y1L1(x) + ynLn(x) (5.7)

    where Li(x)=n

    j=0,j=i

    xxjxi

    xj

    =(xx0) (xxi1)(xxi+1) (xxn)(xi

    x0)

    (xi

    xi1)(xi

    xi)

    (xi

    xn)

    ,

    where Li(xj) = ij

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.1.4 Divided differences

    http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    12/56

    p pp

    Remark; The Lagranges formula (5.7) is suited for theoretical uses,but is impractical for computing the value of an interpolating polynomial:knowing P2(x) does not lead to a less expensive way to compute P3(x).But for this we need some preliminaries, and we start with a discrete version

    of the derivative of a function f(x).Definition (First-order divided difference)

    Let x0 = x1, we define the first-order divided difference of f(x) by

    f[x0, x1] =

    f(x1)

    f(x2)

    x1 x2 (5.8)If f(x) is differentiable on an interval containing x0 and x1, then the meanvalue theorem gives

    f[x0, x1] = f(c), for c between x0 and x1.

    Also if x0, x1 are close together, then

    f[x0, x1] f

    x0 + x12

    usually a very good approximation.

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.1.4 Divided differences

    http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    13/56

    Example

    Let f(x) = cos(x), x0 = 0.2, x1 = 0.3.

    Then

    f[x0, x1] =

    cos(0.3)

    cos(0.2)

    0.3 0.2

    = 0.2473009 (5.9)while

    f

    x0 + x12

    = sin(0.25) = 0.2474040

    so f[x0, x1] is a very good approximation of this derivative.

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.1.4 Divided differences

    http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    14/56

    Higher-order divided differences are defined recursively

    Let x0, x1, x2 R distinct. The second-order divideddifference

    f[x0, x1, x2] =f[x1, x2] f[x0, x1]

    x2 x0 (5.10)

    Let x0, x1, x2, x3 R distinct. The third-order divideddifference

    f[x0, x1, x2, x3] =f[x1, x2, x3] f[x0, x1, x2]

    x3 x0 (5.11)

    In general, let x0, x1, . . . , xn R, n + 1 distinct numbers. Thedivided difference of order n

    f[x0, . . . , xn] =f[x1, . . . , xn] f[x0, . . . , xn1]

    xn x0 (5.12)

    or the Newton divided difference.

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.1.4 Divided differences

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    15/56

    Theorem

    Let n 1, f Cn[, ] and x0, x1, . . . , xn n + 1 distinct numbers in [, ].Then

    f[x0, x1, . . . , xn] =1n!

    f(n)(c) (5.13)

    for some unknown point c between the maximum and the minimum ofx0, . . . , xn.

    Example

    Let f(x) = cos(x), x0 = 0.2, x1 = 0.3, x2 = 0.4.

    The f[x0, x1] is given by (5.9), and

    f[x1, x2] =cos(0.4) cos(0.3)

    0.4 0.3

    = 0.3427550

    hence from (5.11)f[x0, x1, x2]

    =0.3427550 (0.2473009)

    0.4 0.2=

    0.4772705 (5.14)

    For n = 2, (5.13) becomes

    f[x0, x1, x2] =1

    2f(c) = 1

    2cos(c) 1

    2cos(0.3)

    = 0.4776682

    which is nearly equal to the result in (5.14).

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.1.5 Properties of divided differences

    http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    16/56

    The divided differences (5.12) have special properties that help simplify workwith them.(1) Let (i0, i1, . . . , in) be a permutation (rearrangement) of the integers

    (0, 1, . . . , n). It can be shown that

    f[xi0 , xi1 , . . . , xin ] = f[x0, x1, . . . , xn] (5.15)

    The original definition (5.12) seems to imply that the order of x0, x1, . . . , xnis important, but (5.15) asserts that it is not true.

    For n = 1f[x0, x1] =

    f(x0) f(x1)x0 x1 =

    f(x1) f(x0)x1 x0 = f[x1, x0]

    For n = 2 we can expand (5.11) to get

    f[x0, x1, x2] =

    f(x0)

    (x0 x1)(x0 x2) +f(x1)

    (x1 x0)(x1 x2) +f(x2)

    (x2 x0)(x2 x1)(2) The definitions (5.8), (5.11) and (5.12) extend to the case where some or

    all of the xi coincide, provided that f(x) is sufficiently differentiable.

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.1.5 Properties of divided differences

    http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    17/56

    For example, define

    f[x0, x0] = limx1x0

    f[x0, x1] = limx1x0

    f(x0) f(x1)x1 x0

    f[x0, x0] = f(x0)

    For an arbitrary n 1, let all xi x0; this leads to the definition

    f[x0, . . . , x0] = 1n! f(n)(x0) (5.16)

    For the cases where only some of nodes coincide: using (5.15), (5.16)we can extend the definition of the divided difference.For example

    f[x0, x1, x0] = f[x0, x0, x1] =f[x0, x1] f[x0, x0]

    x1 x0 =f[x0, x1] f(x0)

    x1 x0

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.1.5 Properties of divided differences

    http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    18/56

    MATLAB program: evaluating divided differences

    Given a set of values f(x0), . . . , f (xn) we need to calculate the set of

    divided differences

    f[x0, x1], f[x0, x1, x2], . . . , f [x0, x1, . . . , xn]

    We can use the MATLAB function divdif using the function call

    divdif y = divdif(x nodes, y values)Note that MATLAB does not allow zero subscripts, hence x nodes andy values have to be redefined as vectors containing n + 1 components:

    x nodes = [x0, x1, . . . , xn]

    x nodes(i) = xi1, i = 1, . . . , n + 1y values = [f(x0), f(x1), . . . , f (xn)]

    y values(i) = f(xi1), i = 1, . . . , n + 1

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.1.5 Properties of divided differences

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    19/56

    MATLAB program: evaluating divided differences

    function divdif y = divdif(x nodes,y values) %% This is a function% divdif y = divdif(x nodes,y values)% It calculates the divided differences of the function% values given in the vector y values, which are the values of% some function f(x) at the nodes given in x nodes. On exit,% divdif y(i) = f[x 1,...,x i], i=1,...,m% with m the length of x nodes. The input values x nodes and

    % y values are not changed by this program.%divdif y = y values;

    m = length(x nodes);

    for i=2:m

    for j=m:-1:idivdif y(j) = (divdif y(j)-divdif y(j-1)) ...

    /(x nodes(j)-x nodes(j-i+1));

    end

    end

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.1.5 Properties of divided differences

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    20/56

    This program is illustrated in this table.

    i xi cos(xi) Di0 0.0 1.000000 0.1000000E+1

    1 0.1 0.980067 -0.9966711E-1

    2 0.4 0.921061 -0.4884020E+0

    3 0.6 0.825336 0.4900763E-14 0.8 0.696707 0.3812246E-1

    5 1.0 0.540302 -0.3962047E-2

    6 1.2 0.36358 -0.1134890E-2

    Table: Values and divided differences for cos(x)

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.1.6 Newtons Divided Differences

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    21/56

    Newton interpolation formula

    Interpolation of f at x0, x1, . . . , xnIdea: use Pn1(x) in the definition of Pn(x):

    Pn(x) = Pn1(x) + C(x)

    C(x) Pn correction termC(xi) = 0 i = 0, . . . , n 1

    =

    = C(x) = a(x x0)(x x1) . . . (x xn1)Pn(x) = ax

    n + . . .

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.1.6 Newtons Divided Differences

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    22/56

    Definition: The divided difference of f(x) at points x0, . . . , xn

    is denoted by f[x0, x1, . . . , xn] and is defined to be the coefficient ofxn in Pn(x; f).

    C(x) = f[x0, x1, . . . , xn](x x0) . . . (x xn1)pn(x; f) = pn1(x; f)+f[x0, x1, . . . , xn](xx0) . . . (xxn1) (5.17)

    p1(x; f) = f(x0) + f[x0, x1](x x0) (5.18)p2(x; f) = f(x0)+f[x0, x1](xx0)+f[x0, x1, x2](xx0)(xx1) (5.19)...

    pn(x; f) = f(x0) + f[x0, x1](x x0) + . . . (5.20)+f[x0, . . . , xn](x x0) . . . (x xn1)

    = Newton interpolation formula4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.1.6 Newtons Divided Differences

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    23/56

    For (5.18), consider p1(x0), p1(x1). Easily, p1(x0) = f(x0), and

    p1(x1) = f(x0)+(x1x0)

    f(x1)f(x0)x1 x0

    = f(x0)+[f(x1)f(x0)] = f(x1)

    So: deg(p1) 1 and satisfies the interpolation conditions. Then theuniqueness of polynomial interpolation (5.18) is the linearinterpolation polynomial to f(x) at x0, x1.

    For (5.19), note that

    p2(x) = p1(x) + (x x0)(x x1)f[x0, x1, x2]It satisfies: deg(P2) 2 andp2(xi) = p1(xi) + 0 = f(xi), i = 0, 1

    p2(x2) = f(x0) + (x2 x0)f[x0.x1] + (x2 x0)(x2 x1)f[x0, x1, x2]

    = f(x0) + (x2 x0)f[x0.x1] + (x2 x1){f[x1, x2] f[x0, x1]}= f(x0) + (x1 x0)f[x0.x1] + (x2 x1)f[x1, x2]= f(x0) + {f(x1) f(x0)} + {f(x2) f(x1)} = f(x2)

    By the uniqueness of polynomial interpolation, this is the quadraticinterpolating polynomial to f(x) at

    {x0, x1, x2

    }.

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.1.6 Newtons Divided Differences

    http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    24/56

    Example

    Find p(x) P2 such that p(1) = 0, p(0) = 1, p(1) = 4.

    p(x) = p(x0) + p[x0, x1](x x0) + p[x0, x1, x2](x x0)(x x1)

    xi p(xi) p[xi, xi+1] p[xi, xi+1, xi+1]

    1 0 1 10 1 31 4

    p(x) = 0 + 1(x + 1) + 1(x + 1)(x 0) = x2 + 2x + 1

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.1.6 Newtons Divided Differences

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    25/56

    Example

    Let f(x) = cos(x). The previous table contains a set of nodes xi, the values

    f(xi) and the divided differences computed with divdifDi = f[x0, . . . , xi] i 0

    pn(0.1) pn(0.3) pn(0.5)1 0.9900333 0.9700999 0.95016642 0.9949173 0.9554478 0.8769061

    3 0.9950643 0.9553008 0.87764134 0.9950071 0.9553351 0.87758415 0.9950030 0.9553369 0.87758236 0.9950041 0.9553365 0.8775825

    True 0.9950042 0.9553365 0.8775826

    Table: Interpolation to cos(x) using (5.20)

    This table contains the values of pn(x) for various values of n, computed

    with interp, and the true values of f(x).

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.1.6 Newtons Divided Differences

    http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    26/56

    In general, the interpolation node points xineed not to be evenly spaced,nor be arranged in any particular order

    to use the divided difference interpolation formula (5.20)

    To evaluate (5.20) efficiently we can use a nested multiplicationalgorithm

    Pn(x) = D0 + (x x0)D1 + (x x0)(x x1)D2+ . . . + (x

    x0)

    (x

    xn1)Dn

    with D0 = f(x0), Di = f[x0, . . . , xi] for i 1Pn(x) = D0 + (x x0)[D1 + (x x1)[D2 + (5.21)

    + (x xn2)[Dn1 + (x xn1)Dn] ]]For example

    P3(x) = D0 + (x x0)D1 + (x x1)[D2 + (x x2)D3](5.21) uses only n multiplications to evaluate Pn(x) and is more convenient

    for a fixed degree n. To compute a sequence of interpolation polynomials of

    increasing degree is more efficient to se the original form (5.20).

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.1.6 Newtons Divided Differences

    ff f

    http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    27/56

    MATLAB: evaluating Newton divided difference for polynomial interpolation

    function p eval = interp(x nodes,divdif y,x eval) %% This is a function

    % p eval = interp(x nodes,divdif y,x eval)% It calculates the Newton divided difference form of

    % the interpolation polynomial of degree m-1, where the

    % nodes are given in x nodes, m is the length of x nodes,

    % and the divided differences are given in divdif y. The

    % points at which the interpolation is to be carried out% are given in x eval; and on exit, p eval contains the

    % corresponding values of the interpolation polynomial.

    %

    m = length(x nodes);

    p eval = divdif y(m)*ones(size(x eval));

    for i=m-1:-1:1

    p eval = divdif y(i) + (x eval - x nodes(i)).*p eval;

    end

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.2 Error in polynomial interpolation

    F l f E(t) f (t) (t f )

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    28/56

    Formula for error E(t) = f(t)pn(t; f)

    Pn(x) =

    nj=0

    f(xj)Lj(x)

    Theorem

    Let n 0, f Cn+1[a, b], x0, x1, . . . , xn distinct points in [a, b]. Thenf(x) Pn(x) = (x x0) . . . (x xn)f[x0, x1, . . . , xn, x] (5.22)

    =(x x0)(x x1) (x xn)

    (n + 1)!f(n+1)(cx) (5.23)

    for x [a, b], cx unknown between the minimum and maximum ofx0, x1, . . . , xn.

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.2 Error in polynomial interpolation

    P f f Th

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    29/56

    Proof of Theorem

    Fix t

    R. Consider

    pn+1(x; f) interpolates f at x0, . . . , xn, tpn(x; f) interpolates f at x0, . . . , xn

    From Newton

    pn+1(x; f) = pn(x; f) + f[x0, . . . , xn, t](x x0) . . . (x xn)

    Let x = t.

    f(t) := pn+1(t, f) = pn(t; f) + f[x0, . . . , xn, t](t x0) . . . (t x)E(t) := f[x0, x1, . . . , xn, t](t x0) . . . (t xn)

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.2 Error in polynomial interpolation

    E l

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    30/56

    Examples

    f(x) = xn, f[x0, . . . , xn] =n!n! = 1 or

    pn(x; f) = 1

    xn

    f[x

    0, . . . , xn] = 1

    f(x) Pn1, f[x0, x1, . . . , xn] = 0f(x) = xn+1, f[x0, . . . , xn] = x0 + x1 + . . . + xn

    R(x) = xn+1 pn(x; f) Pn+1

    R(xi) = 0, i = 0, . . . , nR(xi) = (x x0) . . . (x xn) = xn+1 (x0 + . . . + xn)xn + . . .

    Pn

    =

    f[x0, . . . , xn] = x0 + x1 + . . . + xn.

    If f Pm,

    f[x0, . . . , xm, x] =

    polynomial degree m n 1 if n m 10 if n > m 1

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.2 Error in polynomial interpolation

    E l

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    31/56

    Example

    Take f(x) = ex, x [0, 1] and consider the error in linear interpolationto f(x) using x0, x1 satisfying 0 x0 x1 1.

    From (5.23)

    ex P1(x) = (x x0)(x x1)2

    ecx

    for some cx between the max and min of x0, x1 and x. Assumingx0 < x < x1, the error is negative and approximately a quadraticpolynomial

    ex P1(x) = (x1 x)(x x0)2

    ecx

    Since x0 cx x1(x1 x)(x x0)

    2ex0 |ex P1(x)| = (x1 x)(x x0)

    2ex1

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.2 Error in polynomial interpolation

    http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    32/56

    For a bound independent of x

    maxx0xx1

    (x1 x)(x x0)2

    =h2

    8

    , h = x1

    x0

    and ex1 e on [0, 1]

    |ex P1(x)| h2

    8e, 0 x0 x x1 1

    independent of x, x0, x1.Recall that we estimated e0.826

    = 2.2841914 by e0.82 and e0.83, i.e.,

    h = 0.01.

    |ex P1(x)| h2

    8e = |ex P1(x)| 0.01

    2

    82.72 = 0.0000340,

    The actual error being 0.0000276, it satisfies this bound.

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.2 Error in polynomial interpolation

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    33/56

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.2 Error in polynomial interpolation

    Example

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    34/56

    Again let f(x) = ex on [0, 1], but consider the quadratic interpolation.

    ex

    P2(x) =(x

    x0)(x

    x1)(x

    x2)

    6 ecx

    for some cx between the min and max of x0, x1, x2 and x.Assuming evenly spaced points, h = x1 x0 = x2 x1, and0 x0 < x < x2 1, we have as before

    |ex P2(x)| (x x0)(x x1)(x x2)6

    e1while

    maxx0xx2(x

    x0

    )(x

    x1

    )(x

    x2

    )

    6 =h3

    93 (5.24)

    hence

    |ex P2(x)| h3e

    9

    3 0.174h3

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.2 Error in polynomial interpolation

    For h = 0.01, 0 x 1

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    35/56

    |ex

    P2(x)| 1.74 107

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.2 Error in polynomial interpolation

    Let ( )(x + h)x(x h) x3 xh

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    36/56

    Let w2(x) =( + ) ( )

    6=

    6

    a translation along x-axis of polynomial in (5.24). Then x = h3

    satisfies

    0 = w2(x) =3x2 h2

    6and gives

    w2 h

    3

    = h393

    Figure: y = w2(x)

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.2.2 Behaviour of the error

    When we consider the error formula (5 23) or (5 22) the polynomial

    http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    37/56

    When we consider the error formula (5.23) or (5.22), the polynomial

    n(x) = (x x0) (x xn)

    is crucial in determining the behaviour of the error. Let assume thatx0, . . . , xn are evenly spaced and x0 x xn.

    Figure: y = 6(x)

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.2.2 Behaviour of the error

    Remark that the interpolation error

    http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    38/56

    is relatively larger in [x0, x1] and [x5, x6], and

    is likely to be smaller near the middle of the node points

    In practical interpolation problems, high-degree polynomial interpolationwith evenly spaced nodes is seldom used.But when the set of nodes is suitable chosed, high-degree polynomials can bevery useful in obtaining polynomial approximations to functions.

    Example

    Let f(x) = cos(x), h = 0.2, n = 8 and then interpolate at x = 0.9.

    Case (i) x0 = 0.8, x8 = 2.4 x = 0.9 [x0, x1]. By direct calculation ofP8(0.9),

    cos(0.9)

    P8(0.9)

    =

    5.51

    109

    Case (ii) x0 = 0.2, x8 = 1.8 x = 0.9 [x3, x4], where x4 is the midpoint.cos(0.9) P8(0.9) = 2.26 1010,

    a factor of 24 smaller than the first case.

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.2.2 Behaviour of the error

    Example

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    39/56

    Le f(x) = 11+x2 , x [5, 5], n > 0 an even integer, h = 10nxj =

    5 + jh, j = 0, 1, 2, . . . , n

    It can be shown that for many points x in [5, 5], the sequence of{Pn(x)}does not converge to f(x) as n .

    Figure: The interpolation to 11+x2

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.3 Interpolation using spline functions

    x 0 1 2 2.5 3 3.5 4

    2 5 0 5 0 5 1 5 1 5 1 125 0

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    40/56

    y 2.5 0.5 0.5 1.5 1.5 1.125 0The simplest method of interpolating data in a table: connecting the nodepoints by straight lines: the curve y = (x) is not very smooth.

    Figure: y = (x): piecewise linear interpolation

    We want to construct a smooth curve that interpolates the given data point

    that follows the shape of y = (x).

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.3 Interpolation using spline functions

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    41/56

    Next choice: use polynomial interpolation. With seven data point, weconsider the interpolating polynomial P6(x) of degree 6.

    Figure: y = P6(x): polynomial interpolation

    Smooth, but quite different from y = (x)!!!

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.3 Interpolation using spline functions

    A third choice: connect the data in the table using a succession of

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    42/56

    A third choice: connect the data in the table using a succession ofquadratic interpolating polynomials: on each [0, 2], [2, 3], [3, 4].

    Figure: y = q(x): piecewise quadratic interpolation

    Is smoother than y = (x), follows it more closely than y = P6(x), butat x = 2 and x = 3 the graph has corners, i.e., q(x) is discontinuous.

    4. Interpolation Math 1070

    >4. Interpolation and Approximation

    >4.3.1 Spline interpolation

    Cubic spline interpolation

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    43/56

    Suppose n data points (xi, yi), i = 1, . . . , n are given and

    a = x1 < . . . < xn = b

    We seek a function S(x) defined on [a, b] that interpolates the data

    S(xi) = yi, i = 1, . . . , n

    Find S(x) C2[a, b], a natural cubic spline such that

    S(x)is a polynomial of degree 3on each subinterval [xj1, xj ], j = 2, 3, . . . , nS(x

    i) = y

    i, i = 1, . . . , n ,

    S(a) = S(b).

    On [xi1, xi]: 4 degrees of freedom (cubic spline) 4(n 1) DOF.

    4. Interpolation Math 1070

    >

    4. Interpolation and Approximation>

    4.3.1 Spline interpolation

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    44/56

    S(xi) = yi : n constraints

    S(xi 0) = S(xi + 0) continuity 2 = 1, . . . , n 1S(xi 0) = S(xi + 0) i = 2, . . . , n 1S(xi 0) = S(xi + 0) i = 2, . . . , n 1

    3n 6

    n + (3n

    6) = 4n

    6 constraints

    Two more constraints needed to be added, Boundary Conditions:

    S = 0 at a = x1, xn = b,

    for a natural cubic spline.(Linear system, with symmetric, positive definite, diagonally dominantmatrix.)

    4. Interpolation Math 1070

    >

    4. Interpolation and Approximation>

    4.3.2 Construction of the cubic spline

    Introduce the variables M1, . . . , M n with

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    45/56

    Mi S(xi), i = 1, 2, . . . , nSince S(x) is cubic on each [xj1, xj ] S(x) is linear, hence determined

    by its values at two points:S(xj1) = Mj1, S(xj) = Mj

    S(x) = (xj x)Mj1 + (x xj1)Mjxj xj1 , xj1 x xj (5.25)

    Form the second antiderivative of S

    (x) on [xj1

    , xj

    ] and apply theinterpolating conditions

    S(xj1) = yj1, S(xj) = yjwe get

    S(x) =

    (xj

    x)3Mj

    1 + (x

    xj

    1)

    3Mj

    6(xj xj1) +(xj

    x)yj

    1 + (x

    xj

    1)yj

    6(xj xj1) 1

    6(xj xj1) [(xj x)Mj1 + (x xj1)Mj ] (5.26)

    for x [xj1, xj ], j = 1, . . . , n.

    4. Interpolation Math 1070

    >

    4. Interpolation and Approximation>

    4.3.2 Construction of the cubic spline

    Formula (5.26) implies that S(x) is continuous over all [a, b] and

    http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    46/56

    satisfies the interpolating conditions S(xi) = yi.Similarly, formula (5.25) for S(x) implies that is continuous on [a, b].To ensure the continuity of S(x) over [a, b]: we require S(x) on[xj1, xj ] and [xj , xj+1] have to give the same value at their commonpointxj , j = 2, 3, . . . , n 1, leading to the tridiagonal linear system

    xj xj16

    Mj1 +xj+1 xj1

    3Mj +

    xj+1 xj6

    Mj+1 (5.27)

    =yj+1 yjxj+1 xj

    yj yj1xj xj1 , j = 2, 3, . . . , n 1

    These n 2 equations together with the assumptionS(a) = S(b) = 0:

    M1 = Mn = 0 (5.28)

    leads to the values M1, . . . , M n, hence the function S(x).

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.3.2 Construction of the cubic spline

    Example

    C l l t th t l bi li i t l ti th d t

    http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    47/56

    Calculate the natural cubic spline interpolating the data(1, 1), (2,

    1

    2), (3,

    1

    3), (4,

    1

    4)

    n = 4, and all xj1 xj = 1. The system (5.27) becomes16M1+

    23M2 +

    16M3 =

    13

    16M2 +

    23M3 +

    16M4 =

    112

    and with (5.28) this yields

    M2 =1

    2, M3 = 0

    which by (5.26) gives

    S(x) =

    1

    12

    x3

    1

    4

    x2

    1

    3

    x + 3

    2

    , 1

    x

    2

    112x3 + 34x2 73x + 176 , 2 x 3 112x + 712 , 3 x 4

    Are S(x) and S(x) continuous?

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.3.2 Construction of the cubic spline

    Example

    C l l t th t l bi li i t l ti th d t

    http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    48/56

    Calculate the natural cubic spline interpolating the datax 0 1 2 2.5 3 3.5 4

    y 2.5 0.5 0.5 1.5 1.5 1.125 0

    n = 7, system (5.27) has 5 equations

    Figure: Natural cubic spline interpolation y = S(x)

    Compared to the graph of linear and quadratic interpolation y = (x) and

    y = q(x), the cubic spline S(x) no longer contains corners.

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.3.3 Other interpolation spline functions

    So far we only interpolated data points, wanting a smooth curve.

    When we seek a spline to interpolate a known function we are interested also

    http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    49/56

    When we seek a spline to interpolate a known function, we are interested also

    in the accuracy.

    Let f(x) be given on [a, b], that we want to interpolate on evenly

    spaced values of x. For n > 1, let

    h =b an 1 , xj = a + (j 1)h, j = 1, 2, . . . , n

    and Sn(x) be the natural cubic spline interpolating f(x) at x1, . . . , xn.

    It can be shown that

    maxaxb

    |f(x) Sn(x)| ch2 (5.29)

    where c depends on f(a), f(b) and maxaxb

    |f(4)(x)

    |. The reason

    why Sn(x) doesnt converge more rapidly (have an error bound with ahigher power of h) is that f(a) = 0 = f(b), while by definitionSn(a) = S

    n(b) = 0. For functions f(x) with f

    (a) = f(b) = 0, theRHS of (5.29) can be replaced with ch4.

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.3.3 Other interpolation spline functions

    To improve on Sn(x), we look for other interpolating functions S(x) thatinterpolate f (x) on

    http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    50/56

    interpolate f(x) ona = x1 < x2 < . . . < xn = b

    Recall the definition of natural cubic spline:

    1 S(x) cubic on each subinterval [xj1, xj ];

    2 S(x), S(x) and S(x) are continuous on [a, b];

    3 S(x1) = S(xn) = 0.

    We say that S(x) is a cubic spline on [a, b] if1 S(x) cubic on each subinterval [xj1, xj ];

    2 S(x), S(x) and S(x) are continuous on [a, b];

    With the interpolating conditions

    S(xi) = yi, i = 1, . . . , n

    the representation formula (5.26) and the tridiagonal system (5.27) arestill valid.

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.3.3 Other interpolation spline functions

    This system has n 2 equations and n unknowns: M1, . . . , M n. Byreplacing the end conditions (5 28) S(x1) = S

    (x ) = 0 we can

    http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    51/56

    replacing the end conditions (5.28) S (x1) = S (xn) = 0, we canobtain other interpolating cubic splines.

    If the data (xi, yi) is obtained by evaluating a function f(x)

    yi = f(xi), i = 1, . . . , n

    then we choose endpoints (boundary conditions) for S(x) that would

    yield a better approximation to f(x). We requireS(x1) = f

    (x1), S(xn) = f

    (xn)

    or

    S(x1) = f(x1), S

    (xn) = f(xn)

    When combined with(5.26-5.27), either of these conditions leads to aunique interpolating spline S(x), dependent on which of theseconditions is used. In both cases, the RHS of (5.29) can be replacedby ch4, where c depends on maxx[a,b]

    f(4)(x)

    .

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.3.3 Other interpolation spline functions

    If the derivatives of f(x) are not known, then extra interpolating

    http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    52/56

    conditions can be used to ensure that the error bond of (5.29) isproportional to h4. In particular, suppose that

    x1 < z1 < x2, xn1 < z2 < xn

    and f(z1), f(z2) are known. Then use the formula for S(x) in (5.26)and

    s(z1) = f(z1), s(z2) = f(z2) (5.30)

    This adds two new equations to the system (5.27), one for M1 andM2, and another equation for Mn1, Mn. This form is preferable tothe interpolating natural cubic spline, and is almost equally easy toproduce. This is the default form of spline interpolation that isimplemented in MATLAB. The form of spline formed in this way issaid to satisfy the not-a-knot interpolation boundary conditions.

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.3.3 Other interpolation spline functions

    http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    53/56

    Interpolating cubic spline functions are a popular way to represent dataanalytically because

    1 are relatively smooth: C2,

    2 do not have the rapid oscillation that sometime occurs with thehigh-degree polynomial interpolation,

    3 are relatively easy to work with on a computer.

    They do not replace polynomials, but are a very useful extension ofthem.

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.3.4 The MATLAB program spline

    http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    54/56

    The standard package MATLAB contains the functionrm spline.

    The standard calling sequence is

    y = spline(x nodes, y nodes, x)

    which produces the cubic spline function S(x) whose graph passes

    through the points {(i, i) : i = 1, . . . , n} with(i, i) = (x nodes(i),y nodes (i))

    and n the length of x nodes (and y nodes). The not-a-knot

    interpolation conditions of (5.30) are used. The point (2, 2) is thepoint (z1, f(z1)) of (5.30) and (n1, n1) is the point (z2, f(z2)).

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.3.4 The MATLAB program spline

    http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    55/56

    Example

    Approximate the function f(x) = ex

    on the interval [a, b] = [0, 1]. Forn > 0, define h = 1/n and interpolating nodes

    x1 = 0, x2 = h, x3 = 2h , . . . , xn+1 = nh = 1

    Using spline, we produce the cubic interpolating spline interpolantSn,1 to f(x). With the not-a-knot interpolation conditions, the nodesx2 and xn are the points z1 and z2 in (5.30). For a general smoothfunction f(x), it turns out that te magnitude of the errorf(x)

    Sn,1(x) is largest around the endpoints of the interval of

    approximation.

    4. Interpolation Math 1070

    > 4. Interpolation and Approximation > 4.3.4 The MATLAB program spline

    Example

    Two interpolating nodes are inserted, the midpoints of the subintervals [0, h]

    http://-/?-http://-/?-http://-/?-
  • 7/29/2019 MATH1070 3 Interpolation

    56/56

    p g p [ , ]and [1 h, 1]:

    x1 = 0, x2 =1

    2h, x3 = h, x4 = 2h , . . . , xn+1 = (n

    1)h, xn+2 = 1

    1

    2h, xn+3 = 1

    Using spline results in a cubic spline function Sn,2(x); with the not-a-knotinterpolation conditions conditions, the nodes x2 and xn+2 are the points z1and z2 of (5.30). Generally, Sn,2 is a more accurate approximation than isSn,1(x).

    The cubic polynomials produced for Sn,2(x) by spline for the intervals[x1, x2] and [x2, x3] are the same, thus we can use the polynomial for [0,12h]

    for the entire interval [0, h]. Similarly for [1 h, h].n E

    (1)n Ratio E

    (2)n Ratio

    5 1.01E-4 1.11E-5

    10 6.92E-6 14.6 7.88E-7 14.120 4.56E-7 15.2 5.26E-8 15.040 2.92E-8 15.6 3.39E-9 15.5

    Table: Cubic spline approximation to f(x) = ex

    4. Interpolation Math 1070

    http://-/?-http://-/?-