# Finding a third degree polynomial that passes through given points

If I have three points xi-1,xi, xi+1 where y(xi) =1 and y(xi-1)=0, y(xi+1)=0 (basis function) and I need to define a line that passes through these points I will use the line equation y-y1=(y2-y1) /(x2-x1) *(x-x1) first trough points (xi-1,xi) and then trough points (xi, xi+1).

My question is how can I define a third degree polynomial (or even higher) trough these three points??

• Look up InterpolatingPolynomial[]. – J. M.'s torpor May 31 '20 at 12:37
• Or look up Lagrange polynomials – Roman May 31 '20 at 16:09
• Lagrange works with simple y=ax+b functions. Now I need Hermite but it's not working when I use HermiteH. – Ilma May 31 '20 at 20:04

Clear["Global*"]


pts = {{xi - 1, 0}, {xi, 1}, {xi + 1, 0}};


InterpolatingPolynomial finds the lowest degree polynomial fitting the points. For three points this is a second degree polynomial.

f[x_] = InterpolatingPolynomial[pts, x]

(* (1 + x - xi) (1 - x + xi) *)


To find a higher degree polynomial add additional points at arbitrary unique locations.

poly[degree_Integer?(# > 1 &)][x_] :=
InterpolatingPolynomial[
Join[pts, {xa[#], ya[#]} & /@ Range[degree - 2]], x] //
FullSimplify


Verifying that poly of degree 2 is identical to f

f[x] === poly[2][x]

(* True *)


The third degree polynomial is

poly[3][x]

(* (1 + x - xi) (1 + (x -
xi) (-1 + ((-1 + x - xi) (1 + (
1 + ya[1]/(-1 - xi + xa[1]))/(-xi + xa[1])))/(1 - xi + xa[1]))) *)


Verifying that this polynomial passes through the original points

pts === ({#, poly[3][#]} & /@ {xi - 1, xi, xi + 1})

(* True *)

• Thank you for the answer. I tried with this approach and it worked but I am having trouble plotting the function when the interval is [0,1]. Do you have any idea why it wouldn't work with plot[poly[3][x],{x,0,1}] ? – Ilma May 31 '20 at 19:47
• Did you assign values to xi, xa[1], and ya[1]? – Bob Hanlon May 31 '20 at 19:50
• No, I need it to work with any arbitrary interval [xi, xi+1] or [xi-1,xi]. Do I have to assign them? I don't really know any values except that it's 1 at xi and 0 at xi-1 and xi+1 – Ilma May 31 '20 at 20:27
• You must assign values to plot. – Bob Hanlon May 31 '20 at 20:29
• Oh, alright. Thanks again, you've really helped a lot. – Ilma May 31 '20 at 20:40

The associated coefficients for a k-th degree polynomial to fit through {{xi-1,0},{xi,1},{xi+1,0}} can be found through Solve (better for k=2) and Reduce (for k=3 and k=4). While I'm I don't understand the desire for doing this for k=3 and k=4, I certainly wouldn't recommend do this for k > 4.

(* Quadratic *)
Solve[{a[0] + a[1] xi + a[2] xi^2 == 1,
a[0] + a[1] (xi - 1) + a[2] (xi - 1)^2 == 0,
a[0] + a[1] (xi + 1) + a[2] (xi + 1)^2 == 0},
{a[0], a[1], a[2]}]
(* {{a[0] -> 1-xi^2,a[1] -> 2 xi,a[2] -> -1}} *)

(* Cubic *)
Reduce[{a[0] + a[1] xi + a[2] xi^2 + a[3] xi^3 == 1,
a[0] + a[1] (xi - 1) + a[2] (xi - 1)^2 + a[3] (xi - 1)^3 == 0,
a[0] + a[1] (xi + 1) + a[2] (xi + 1)^2 + a[3] (xi + 1)^3 == 0},
{a[0], a[1], a[2], a[3]}]


(* Quartic *)
k = 4
Reduce[{Sum[a[i] xi^i, {i, 0, k}] == 1,
Sum[a[i] (xi - 1)^i, {i, 0, k}] == 0,
Sum[a[i] (xi + 1)^i, {i, 0, k}] == 0}, Table[a[i], {i, 0, k}]]
`

• I don't really need the coefficients, I need to define basis functions w and z that are constructed of Hermite basis interpolation polynomials so I can get a third degree polynomial v with which I am approximating a solution u of PDE of 4th order (precisely the elliptic PDE of fourth order with Dirichlet and Neumanns boundary conditions). I tried using HermiteH but it's not really doing the job so I'm trying out different methods. When it was a PDE of first order I just used the line equation formula and it was easy. – Ilma May 31 '20 at 20:00
• OK. Next time you should add such information to your question. You'll get more targeted answers. – JimB May 31 '20 at 20:55