# Interpolating and plotting from a list

I have a dataset in this form (but much bigger of course):

{{0.01, 0.227202, 1030., 44., 1555.63, 4.72143},
{0.01, 0.227202, 1030., 84., 2969.85, 4.806},
{0.01, 0.227202, 1030., 124., 4384.06, 4.82289},
{0.1, -0.169967, 1030., 440., 1555.63, 12.1294},
{0.1, -0.169967, 1030., 840., 2969.85, 12.5309}}


where the last (6th) value in each nested list is the dependent variable and the first five are independent. I've made this list by scanning across the dependent variable and solving DE's yielding a result (6th value).

I want to create an interpolating function out of the list. I am able to make such functions (example code):

data = Flatten[Table[{x, y, z, x^2*y*z^2}, {x, 1, 50, 10}, {y, 1, 50, 10}, {z, 1,
50, 10}], 2]
dataint = Interpolation[data, InterpolationOrder -> 1]


this seems to work, generating a similarly structured nested list as my actual dataset, and with random test values:

dataint[14.21, 27.54, 21.99]


I am able to get the interpolated value for the 4th parameter of the lists in 'data', taken here to be the dependent variable. I can plot regions: RegionPlot[dataint[x, y, 1] < 500, {x, 1, 50}, {y, 1, 50}] etc.

How would I create an interpolating function out of my dataset? It has 5 independent variables, and one dependent one. Eventually I want to be able to generated interpolated values (as with dataint) as well as make 2D and 3D plots and regionplots where all but 2 or 3 of the independent variables are kept constant.

Using the following suggestion from Lukas Lang in comments unfortunately highlights further problems:

Interpolation[{Most@#, Last@#} & /@ data]


In fact, the above returns:

Interpolation::indim: The coordinates do not lie on a structured tensor product grid.

How can I get around that?

• Interpolation[{Most@#, Last@#} & /@ data]? – Lukas Lang Jun 25 '18 at 14:51
• @LukasLang - I am getting the error Interpolation::indim: The coordinates do not lie on a structured tensor product grid. – SarahThompson Jun 25 '18 at 15:30
• @LukasLang - and if I use ListInterpolation I get The order-1 derivative of 0.227202 is not a tensor of rank 1 with dimensions 2. – SarahThompson Jun 25 '18 at 15:51
• Did you try with the example data set or the real one? The example data set is too small to give a meaningful interpolation… – Lukas Lang Jun 25 '18 at 16:51
• Interesting… the issue only occurs for coordinate dimensions higher than 3. See this question for more information - unfortunately, there is no answer to that one – Lukas Lang Jun 25 '18 at 16:55

See this example

data = Flatten[
Table[{x, y, z, r, s, Sin[x^2 Sqrt[y] z r^3 s^4]}, {x, 0,
1, .2}, {y, 0, 1, .2}, {z, 0, 1, .2}, {r, 0, 1, .2}, {s, 0,
1, .2}], 4];

data2 = data /. {x_, y_, z_, r_, s_, f_} -> {{x, y, z, r, s}, f};

dint = Interpolation[data2]

dint[.3, .4, .5, .6, .7]

(*   0.00147047   *)

Plot3D[dint[.3, y, .5, .1, s], {y, 0, 1}, {s, 0, 1}, PlotRange -> All] 