2

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?

MarcoB
  • 67,153
  • 18
  • 91
  • 189
SarahThompson
  • 425
  • 2
  • 8
  • 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
  • If you cannot re-sample your function on a regular complete grid, you might be interested in this: Non-Grid Interpolation Package. See also this answer by bbgodfrey for an explanation of this behavior and this Q&A for further discussion. – MarcoB Jun 25 '18 at 19:02
  • @LukasLang - It seems to be working for me for higher than 3 dimensions, for a simple data set (but not for the real one). Do you think the issue could be that I am scanning across the first value logarithmically? – SarahThompson Jun 27 '18 at 19:10
  • @MarcoB - Thank you. I suspect the problem arises because I am scanning logarithmically across some of the values, thereby leaving a structured linear grid - what do you think? – SarahThompson Jun 27 '18 at 19:11
  • @SarahThompson How does this "simple data set" look like? As far as I know, Interpolation supports arbitrary dimensions, as long as the grid is structured (that's also what the error message is saying). Structured here means "lying on a regular grid", such as the data in @Akku14's answer. As @MarcoB was saying, you either need to find a way to get samples on a regular grid or look at the links he provided – Lukas Lang Jun 27 '18 at 19:29
  • @Sarah, I think that’s very possibly the problem. Is it feasible to rescan that variable on a linear grid? – MarcoB Jun 28 '18 at 04:22

1 Answers1

2

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]

enter image description here

Akku14
  • 17,287
  • 14
  • 32