# Maple example for interpolating polynomials -- 3/27 # CS 323 - Doug DeCarlo # Lagrange interpolation L0 := x -> (x-x1)*(x-x2)/((x0-x1)*(x0-x2)); L1 := x -> (x-x0)*(x-x2)/((x1-x0)*(x1-x2)); L2 := x -> (x-x0)*(x-x1)/((x2-x0)*(x2-x1)); P2 := x -> L0(x)*y0 + L1(x)*y1 + L2(x)*y2; collect(P2(x), x); # Let's look at the quadratic coefficient simplify(coeff(P2(x), x, 2)); # ---- # Newton divided differences for interpolation dd01 := (y1 - y0)/(x1-x0); dd12 := (y2 - y1)/(x2-x1); dd012 := (dd12-dd01)/(x2-x0); P1n := x -> y0 + dd01*(x-x0); P2n := x -> P1n(x) + dd012*(x-x0)*(x-x1); # Are they the same? (Yes -- this produces zero) simplify(P2(x) - P2n(x));