Nf2 - Lagrange's interpolating polynomial

Nf2 - Lagrange's interpolating polynomial

Nf2 constructs an interpolating polynomial from distinct data nodes, including unequally spaced nodes. You will build Lagrange's basis factors, combine three or four values, evaluate an interpolant efficiently, and explain when Newton and Lagrange give the same result.

Build one selector polynomial for each data value

Can Lagrange's method give a more accurate interpolating quadratic than Newton's method from exactly the same three points? No: there is only one polynomial of degree at most 22 through three distinct input nodes. The methods write that polynomial differently.

You already know

Newton's forward formula requires equal input spacing. An interpolating polynomial passes through the selected nodes; it need not equal an unknown function between them. n+1n+1 distinct nodes determine a polynomial of degree at most nn.

Lagrange's construction does not require equal spacing. Consider nodes 0,1,30,1,3. The polynomial

L0(x)=(x−1)(x−3)(0−1)(0−3)=(x−1)(x−3)3L_0(x)=\frac{(x-1)(x-3)}{(0-1)(0-3)} =\frac{(x-1)(x-3)}3

is 11 at node 00 and 00 at the other two nodes. Multiplying it by the value at node 00 adds exactly that value there, without changing the other nodes.

Lagrange basis polynomial

For distinct nodes x0,…,xnx_0,\ldots,x_n, the basis polynomial LrL_r equals 11 at its own node xrx_r and 00 at every other node. It has a factor x−xix-x_i for each i≠ri\ne r, and a denominator that makes its own-node value equal to 11.

Add one such selector for each data value. Distinct input nodes are essential: repeated inputs would make a denominator zero, and two different outputs at the same input cannot be values of one function.

[DIAGRAM: asset_name: Three Lagrange selector polynomials; asset_slug: h645_b135_basis; caption: Each basis polynomial is one at its own node and zero at the other nodes; description: Three coordinate panels show L0 equals (x minus one)(x minus three) divided by three, L1 equals x(x minus three) divided by minus two, and L2 equals x(x minus one) divided by six. Each panel marks the nodes zero, one and three, with its own-node point at height one and other-node points at height zero. Equal spacing is not assumed.]
Each basis polynomial is one at its own node and zero at the other nodes

Lagrange's interpolating polynomial

Given n+1n+1 pairs (xr,f(xr))(x_r,f(x_r)) with distinct xrx_r,

Pn(x)=∑r=0nf(xr)Lr(x)P_n(x)=\sum_{r=0}^{n}f(x_r)L_r(x)

where

Lr(x)=∏i=0i≠rnx−xixr−xiL_r(x)=\prod_{\substack{i=0\\i\ne r}}^{n} \frac{x-x_i}{x_r-x_i}

The polynomial has degree at most nn and satisfies Pn(xr)=f(xr)P_n(x_r)=f(x_r) at every selected node. Equal spacing is allowed but not required.

In the formula booklet.

For three nodes, each basis has two numerator factors. Keep the input values in these factors and denominators; the output values belong as multiplying coefficients.

Worked example 1: three unequally spaced nodes

Question. Find the interpolating quadratic through (0,1),(1,3),(3,13)(0,1),(1,3),(3,13).

Plan. Construct the three basis factors, multiply by the corresponding outputs and collect powers of xx.

L0(x)=(x−1)(x−3)3denominator (−1)(−3)L1(x)=x(x−3)−2denominator (1)(−2)L2(x)=x(x−1)6denominator (3)(2)\begin{aligned} L_0(x)&=\frac{(x-1)(x-3)}3 && \text{denominator }(-1)(-3)\\ L_1(x)&=\frac{x(x-3)}{-2} && \text{denominator }(1)(-2)\\ L_2(x)&=\frac{x(x-1)}6 && \text{denominator }(3)(2) \end{aligned} P2(x)=(x−1)(x−3)3−32x(x−3)+136x(x−1)weight by 1,3,13=x2+x+1expand and collect\begin{aligned} P_2(x)&=\frac{(x-1)(x-3)}3-\frac32x(x-3) +\frac{13}{6}x(x-1) && \text{weight by }1,3,13\\ &=x^2+x+1 && \text{expand and collect} \end{aligned}

Why this step? A term's denominator uses its own node minus each other node. The signs are part of the formula, not optional adjustments.

Answer. P2(x)=x2+x+1P_2(x)=x^2+x+1.

Check. P2(0)=1P_2(0)=1, P2(1)=3P_2(1)=3, P2(3)=13P_2(3)=13.

Change only the middle output from 33 to 44. The nodes, and therefore all three basis polynomials, stay unchanged.

Worked example 2: changing one observed value

Question. Find the interpolant through (0,1),(1,4),(3,13)(0,1),(1,4),(3,13).

Plan. Change the coefficient of L1L_1 while retaining the same basis factors.

P2(x)=(x−1)(x−3)3−2x(x−3)+136x(x−1)new middle output 4=12x2+52x+1collect coefficients\begin{aligned} P_2(x)&=\frac{(x-1)(x-3)}3-2x(x-3) +\frac{13}{6}x(x-1) && \text{new middle output }4\\ &=\frac12x^2+\frac52x+1 && \text{collect coefficients} \end{aligned}

Why this step? Basis factors depend only on the input nodes. Changing one output changes only its weight.

Answer. P2(x)=12x2+52x+1P_2(x)=\frac12x^2+\frac52x+1.

Check. The new value at 11 is 44, while the values at 00 and 33 remain 11 and 1313.

Three nodes permit degree 22, but do not force it: the quadratic coefficient can cancel. This is why “degree at most nn” matters.

Watch out

Wrong: put the function values 1,4,131,4,13 into the numerator factors in place of the input nodes 0,1,30,1,3.

Right: factors locate the input nodes; the tabulated outputs multiply those factors.

Change only the middle output once more, watching the degree.

Four distinct nodes allow a cubic

With four nodes, each basis polynomial contains three factors, so the combined interpolant has degree at most 33. The spacing can change from one pair of nodes to the next.

For nodes 0,1,2,40,1,2,4, the denominator for the node 44 is (4−0)(4−1)(4−2)=24(4-0)(4-1)(4-2)=24. The missing node at 33 does not need to be invented.

Worked example 3: a cubic from four nodes

Question. Construct the interpolating cubic through (0,1),(1,2),(2,9),(4,65)(0,1),(1,2),(2,9),(4,65).

Plan. Use all four distinct nodes, with one cubic basis term per output.

P3(x)=−(x−1)(x−2)(x−4)8+23x(x−2)(x−4)−94x(x−1)(x−4)+6524x(x−1)(x−2)four output-weighted terms\begin{aligned} P_3(x)&=-\frac{(x-1)(x-2)(x-4)}8\\ &\quad+\frac23x(x-2)(x-4)\\ &\quad-\frac94x(x-1)(x-4)\\ &\quad+\frac{65}{24}x(x-1)(x-2) && \text{four output-weighted terms} \end{aligned} coefficient of x3=−18+23−94+6524=1cubic coefficientP3(x)=x3+1other non-constant coefficients cancel\begin{aligned} \text{coefficient of }x^3&=-\frac18+\frac23-\frac94+\frac{65}{24}=1 && \text{cubic coefficient}\\ P_3(x)&=x^3+1 && \text{other non-constant coefficients cancel} \end{aligned}

Why this step? There are four data values, so omitting one basis term generally fails to interpolate one of the nodes.

Answer. P3(x)=x3+1P_3(x)=x^3+1.

Check. Substitution at 0,1,2,40,1,2,4 gives 1,2,9,651,2,9,65.

Change only the last output from 6565 to 7777. The first three outputs and every input node stay fixed.

Continue this lesson.

You’re previewing NovaLearn without an account. Create a free account to read the rest.

Create free account