I have a small problem with ListInterpolation. I want to use ListInterpolation to postprocess result of a numerical simulation. Therefore, I give the function (2D) and its first and second derivatives to ListInterpolation.

When I do so, it works with the method "Hermite". But if I switch to "Spline", I receive the warning, that the method "Spline" could not be used because "the data could not be coerced to machine real numbers".

A = ListInterpolation[data, {sigAxis, muAxis}, Method -> "Spline", InterpolationOrder -> 5];

ListInterpolation::mspl: The Spline method could not be used because the data could not be coerced to machine real numbers.

I want to use "Spline" because I want to have accurate derivatives.

I checked the Mathematica manual and googled to learn what I have to do to ensure that the data can be coerced to machine real numbers. Unfortunately without any sucess at all.

Could anyone give me some pointers?

  • $\begingroup$ What do you mean by you "give it the function"? ListInterpolation needs a list of points, not a functional form. What does your data/input look like? $\endgroup$ – bill s May 7 '13 at 15:15
  • $\begingroup$ with "give it the function" I meant the list of points containing the function and it's derivatives $\endgroup$ – david May 7 '13 at 15:33
  • $\begingroup$ Could you perhaps provide a small example of code that exhibits this problem? $\endgroup$ – Sjoerd C. de Vries May 7 '13 at 17:14
  • $\begingroup$ @SjoerdC.deVries, try for example ListInterpolation[Table[Evaluate[{Sin[8 x], D[Sin[8 x], x]}], {x, 0, 3, 0.5}], {{0, 3}}, Method -> "Spline"] $\endgroup$ – Simon Woods May 7 '13 at 18:21
  • $\begingroup$ @SimonWoods Well your example looks like "Spline" and the prescription of derivatives does not work together at all - i thought it is a special problem of data I provided. $\endgroup$ – david May 8 '13 at 10:31

Here's a 2D example to get you started. First, make up some data that has the right format:

list2D = Flatten[Table[{{i, j}, RandomReal[]}, {i, 1, 5}, {j, 1, 5}], 1]

You might want to make sure your data has the right number of parenthesis and nesting of lists, like list2D. Now make an interpolating function using the spline method. Note that this does not require the derivatives as input (it takes the points and constructs a surface that has smooth derivatives).

interpList2D = Interpolation[list2D, Method -> "Spline"]

You can now plot the points and the interpolating surface:

Show[ListPointPlot3D[Partition[Flatten[list2D], 3], ImageSize -> 300, 
     Filling -> Axis, PlotStyle -> PointSize[0.04]], 
     Plot3D[interpList2D[x, y], {x, 1, 5}, {y, 1, 5}]]

The result is as you might expect, a smooth surface that goes through the specified points.

enter image description here

  • $\begingroup$ Thanks, but that does not help me. I've it working, but only with the Method "Hermite", but I want to use "Spline" because of the higher accuracy in the derivatives. But Mathematica tells me it cannot use Spline because "the data could not be coerced to machine real numbers". Actually I plug in data with about 18 digits precision (and 15 in the first derivative and 12 in the second) but after some simple postprocessing with third derivatives I end up with 6 digits precision, which I find is very low. $\endgroup$ – david May 7 '13 at 17:20
  • $\begingroup$ What I actually do is: A = ListInterpolation[data, {sigAxis, muAxis}, Method -> "Spline", InterpolationOrder -> 5]; and I get: ListInterpolation::mspl: The Spline method could not be used because the data could not be coerced to machine real numbers $\endgroup$ – david May 7 '13 at 17:23
  • 2
    $\begingroup$ I'll have to echo Sjoerd C. de Vries here: we can't help you if we cannot reproduce the problem. Give us a (nonworking) example and we can try to see what's wrong. $\endgroup$ – bill s May 7 '13 at 17:59

The reason you are getting the error message you quote is because of an ill-formed domain specification. You specify a 1-D domain where a 2-D domain is required. So let's correct that.

f = ListInterpolation[
  Table[Evaluate[{Sin[8 t], D[Sin[8 t], t]} /. t -> x], {x, 0, 3,  0.05}], 
  {{-1, 1}, {-7, 8}}, 
  Method -> "Spline"];

This still gives a message

ListInterpolation::inhr: Requested order is too high; order has been reduced to {3,1}. >>

However, the evaluation returns a perfectly usable interpolating function, so the message may be considered as a FYI or warning. As can be seen below, the interpolating function plots nicely


However, I can not imagine this is what you want, because ListInterpolation has no way of knowing the the second element of each of your data points is the value of the derivative at the x-value that produced the first element. Adding the option Method -> "Spline" doesn't magically reveal to ListInterpolation your intent.

What you really want (even if you think otherwise) is much more simple.

f = ListInterpolation[Table[Sin[8 x], {x, 0, 3, 0.1}], {{0, 3}}, 
  Method -> "Spline"];
Plot[f[x], {x, 0., 3.}]


And, no, you don't get to specify the derivatives. You leave that to ListInterpolation.

  • $\begingroup$ Thanks, I had done this and it works, but I want to specify the derivatives to get a higher accuracy. I want to calculate plenty of things with the data. With only giving the data without any derivatives I end up with about '10^{-6}' (actually the same range as with Hermite & derivatives) - that's not really good. $\endgroup$ – david May 8 '13 at 9:10
  • $\begingroup$ @user7331. It may be that ListInterpolation won't work for you. It's hard to say what would help because you give so little detail about your problem in your question. Have you looked at this example? $\endgroup$ – m_goldberg May 8 '13 at 21:32
  • $\begingroup$ I have not seen this example, but it does not help me. My problem is that I have a 2D grid with data I want to interpolate in Mathematica in a very accurate way. The nicest thing I could imagine would be Chebyshev-polynoms, but that's unfortunately not implemented. That is why I tried the ListInterpolation with Splines and prescribed derivatives which unfortunately failed (because Spline + Derivatives does not work at all). $\endgroup$ – david May 13 '13 at 7:52

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.