3
$\begingroup$

I am trying to use the InterpolatingPolynomial function in Mathematica to find a polynomial in 2 variables which fits some given data. However, Mathematica often fails to find a polynomial fitting my data even in cases where I already know of a polynomial which fits. For example, I run the following code:

InterpolatingPolynomial[{{{4, 4}, 52}, {{4, 6}, 120}, {{4, 8}, 212}, {{6, 4}, 120}, {{6, 6}, 256}, {{6, 8}, 432}, {{8, 4}, 212}, {{8, 6}, 432}, {{8, 8}, 708}}, {w, z}]

I receive the error message:

InterpolatingPolynomial::poised: The interpolation points {{4,4},{4,6},{4,8},{6,4},{6,6},{6,8},{8,4},{8,6},{8,8}} are not poised, so an interpolating polynomial of total degree 3 could not be found.

However, the above data comes from the polynomial p(w,z) = w z^2 + w^2 z - z^2 - w^2 - 3 w z + 4.

I am not very familiar with the techniques used to find an interpolating polynomial. Is there an explanation for this?

$\endgroup$

3 Answers 3

3
$\begingroup$

This error is coming up due to a limitation of InterpolatingPolynomial. In particular, according to the documentation: for data with abscissas lying on a line in 2 dimensions an interpolant may not be found. You can get around this for your data by removing the middle point:

FullSimplify[
 InterpolatingPolynomial[{{{4, 4}, 52}, {{4, 6}, 120}, {{4, 8}, 
    212}, {{6, 4}, 120}, {{6, 8}, 432}, {{8, 4}, 212}, {{8, 6}, 
    432}, {{8, 8}, 708}}, {w, z}]]
(*4 + w^2 (-1 + z) + w (-3 + z) z - z^2*)

This expression is the same as the known polynomial:

FullSimplify[
 4 + w^2 (-1 + z) + w (-3 + z) z - z^2 == 
  w z^2 + w^2 z - z^2 - w^2 - 3 w z + 4]
(*True*)

If you are not tied to a closed form solution, Interpolation might be a convenient numeric alternative:

func = Interpolation[{{{4, 4}, 52}, {{4, 6}, 120}, {{4, 8}, 
    212}, {{6, 4}, 120}, {{6, 6}, 256}, {{6, 8}, 432}, {{8, 4}, 
    212}, {{8, 6}, 432}, {{8, 8}, 708}}, InterpolationOrder -> 2];
Show[Plot3D[func[w, z], {w, 4, 8}, {z, 4, 8}], 
 ListPointPlot3D[{{{4, 4}, 52}, {{4, 6}, 120}, {{4, 8}, 212}, {{6, 4},
      120}, {{6, 6}, 256}, {{6, 8}, 432}, {{8, 4}, 212}, {{8, 6}, 
     432}, {{8, 8}, 708}} /. {{a_, b_}, c_} :> {a, b, c}, 
  PlotStyle -> PointSize[Large]]]

enter image description here

$\endgroup$
2
  • $\begingroup$ Hi Marchi; It seems removing any of the points will get an answer but it has the undesirable property of making the system underdetermined so there are an infinite number of fits to that 7 point data. $\endgroup$
    – bobbym
    Feb 3, 2017 at 22:27
  • 1
    $\begingroup$ But +1 for your idea of removing a point instead of adding 2 as I did in my first answer. It may not be possible to get more points but we can always remove some. $\endgroup$
    – bobbym
    Feb 3, 2017 at 22:40
2
$\begingroup$

InterpolatingPolynomial often doesn't do well with data on a regularly spaced grid. A random grid of nine point works here.

 p[w_, z_] := w z^2 + w^2 z - z^2 - w^2 - 3 w z + 4
 SeedRandom[42];
 data = 
   Catenate@Table[{{w, z}, p[w, z]},
     {w, RandomSample[Range[100], 3]}, {z, RandomSample[Range[100], 3]}];
 poly = InterpolatingPolynomial[data, {w, z}]

4 - z^2 + w (w (-1 + z) + (-3 + z) z)

 Expand[poly]

4 - w^2 - 3 w z + w^2 z - z^2 + w z^2

$\endgroup$
0
1
$\begingroup$

To start you off this works:

InterpolatingPolynomial[{{{4, 4}, 52}, {{4, 6}, 120}, {{4, 8}, 
   212}, {{6, 4}, 120}, {{6, 6}, 256}, {{6, 8}, 432}, {{8, 4}, 
   212}, {{8, 6}, 432}, {{8, 8}, 708}, {{10, 6}, 648}, {{10, 8}, 
   1040}}, {w, z}]//Expand

(4 - w^2 - 3 w z + w^2 z - z^2 + w z^2)

Maybe you did not have enough points before to uniquely determine all the coefficients.

The above answer is not the best way to handle this. When you know you are right and Mma is not then you should roll your own:

fun[l_] := Module[{w, z},
  w = First[l[[1]]];
  z = Last[l[[1]]];
  h + g*w^2 + f*w^3 + e*w* z + d*w^2* z + c*z^2 + b*w* z^2 + a*z^3 == 
   l[[2]]]

pts = {{{4, 4}, 52}, {{4, 6}, 120}, {{4, 8}, 212}, {{6, 4}, 
    120}, {{6, 6}, 256}, {{8, 4}, 212}, {{8, 6}, 432}, {{8, 8}, 708}};

rul = Solve[fun[#] & /@ pts, {a, b, c, d, e, f, g, h}]

(* {{a -> 0, b -> 1, c -> -1, d -> 1, e -> -3, f -> 0, g -> -1, h -> 4}} *)

(h + g*w^2 + f*w^3 + e*w* z + d*w^2* z + c*z^2 + b*w* z^2 + 
   a*z^3) /. rul

{4 - w^2 - 3 w z + w^2 z - z^2 + w z^2}

Which is what you want. This does not require any changes to the data so disregard my earlier solution.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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