1
$\begingroup$

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??

$\endgroup$
3
  • 4
    $\begingroup$ Look up InterpolatingPolynomial[]. $\endgroup$ May 31, 2020 at 12:37
  • 1
    $\begingroup$ Or look up Lagrange polynomials $\endgroup$
    – Roman
    May 31, 2020 at 16:09
  • $\begingroup$ Lagrange works with simple y=ax+b functions. Now I need Hermite but it's not working when I use HermiteH. $\endgroup$
    – Ilma
    May 31, 2020 at 20:04

2 Answers 2

2
$\begingroup$
Clear["Global`*"]

Your specified points are

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 *)
$\endgroup$
5
  • $\begingroup$ 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}] ? $\endgroup$
    – Ilma
    May 31, 2020 at 19:47
  • $\begingroup$ Did you assign values to xi, xa[1], and ya[1]? $\endgroup$
    – Bob Hanlon
    May 31, 2020 at 19:50
  • $\begingroup$ 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 $\endgroup$
    – Ilma
    May 31, 2020 at 20:27
  • $\begingroup$ You must assign values to plot. $\endgroup$
    – Bob Hanlon
    May 31, 2020 at 20:29
  • $\begingroup$ Oh, alright. Thanks again, you've really helped a lot. $\endgroup$
    – Ilma
    May 31, 2020 at 20:40
0
$\begingroup$

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]}]

Coefficients for k=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}]]

Coefficients for k=4

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$
    – Ilma
    May 31, 2020 at 20:00
  • $\begingroup$ OK. Next time you should add such information to your question. You'll get more targeted answers. $\endgroup$
    – JimB
    May 31, 2020 at 20:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.