Message Boards Message Boards

Interpolation for multi-dimensional functions

Posted 8 years ago

Dear fellow forum members,

Who can help me with the following problem?

I have a list that looks as follows: { {f1,x1,y1}, {f2,x2,y2}, ...}. I wish to express f as a function of x and y by use of Mathematica's ListInterpolation. The documentation for ListInterpolation tells me that I must use the following syntax: ListInterpolation[list,{{x1,x2,...},{y1,y2,....}}]. In other words: it looks as if my data points must be defined on all the intersection points of a grid of perpendicular lines in the (x,y)-plane. In the data set I am working with, this is not the case (i.e. the (x,y) in my data set don't form a rectangular grid.)
I cannot imagine that Mathematica is so restrictive. There must be a good workaround for this.

Does anybody have a good idea?

Thanks in advance,

René Samson

POSTED BY: Rene Samson
10 Replies
Posted 8 years ago

Hi Sander, Thanks for pointing me in the right direction for help and documentation. Thanks, René

POSTED BY: Rene Samson
Posted 8 years ago

Hi Frank,

I've just tested your proposal on my dataset and your suggestion to apply Union[] did the trick. It actually didn't compress my data set, so apparently the problem was not a result of duplicates but of disorder. I had actually tried to fiddle around with this on my own, without realizing that Union[] also orders multi-dimensional sets. Now the Interpolation[] function works without any hickups. WONDERFUL!! I am really thankful to you for pointing this out to me. You saved my day!! Thanks again. (Suggestion to the professional Wolfram crowd: Wouldn't it be nice to give this as an example in the help documentation for Interpolation? I am probably not going to be the first or the last person to run into this difficulty with multi-dimensional functions). René Samson

POSTED BY: Rene Samson

At the bottom of (nearly) each page you have a 'see also' section, which also shows Interpolation in this case. Also at the very the top, on the right, you have a button Tutorials which shows: tutorial/ApproximateFunctionsAndInterpolation Which explains at length how interpolation can be done in Mathematica.

POSTED BY: Sander Huisman

Hello Rene,

I'm very happy you had success! However, I'm very puzzled as to why my suggestion worked at all, if it did not identify (near) duplicate samples. Oh well, onward! :-)

POSTED BY: Frank Iannarilli
Posted 8 years ago

Hi Frank,

I am pretty convinced now that the problem I had was not one of (near) duplicates but one of ordering. After I saw that a Union[] operation of the basic data solved the problem, I subsequently repeated the calculation, using Sort[] instead of Union[] on my basic data and this - likewise - resulted in success. So, my original basic data set apparently was so disordered that it made Interpolation[] impossible. Sorting resolved this problem. At least, that's how I interpreted my experiences. Thanks again for your help.

René

POSTED BY: Rene Samson

Hi Rene,

My guess is that some of your data samples are duplicates (in {x.,y}) or nearly so. To detect them, you might try processing the {x,y} components of your data set through the Union[] function. Does Union return a list of the same Length[] as the one you submitted as its argument? A refinement is to look for small differences between {x,y}i and {x,y}j by using the SameTest option of Union:

sortedList=Union[myList,SameTest-> (Abs[#1[[1]]-#2[[1]]]<epsilon || Abs[#1[[2]]-#2[[2]]]<epsilon &)]

where epsilon is a small number that you can choose, and I assume your list elements are in the form {x,y,f}.

POSTED BY: Frank Iannarilli
Posted 8 years ago

David,

I just tried to use this (my data set is humongously large with about 800,000 {x,y,f} elements) and Interpolation gives me the following set of discouraging reactions: 1. Interpolation::udeg: Interpolation on unstructured grids is currently only supported for InterpolationOrder->1 or InterpolationOrder->All. Order will be reduced to 1. >> 2. Interpolation::femimq: The element mesh has insufficient quality of -1.27917*10^-26. A quality estimate below 0. may be caused by a wrong ordering of element incidents or self-intersecting elements. >> 3. Interpolation::fememtlq: The quality -1.27917*10^-26 of the underlying mesh is too low. The quality needs to be larger than 0.`. >>

I tried doing some reordering of my original data set but also this reordered set didn't work and gave the same comments.

Do you have any idea what's going wrong and what I can do to break this deadlock?

René

POSTED BY: Rene Samson
Posted 8 years ago

You're very welcome, Rene. Notice that ListInterpolation assumes the independent variable(s) takes on either the list indices or values from a specified range, divided over the elements. There is no way to give the y values for specific xi values. That is what Interpolation does. Also, you can expect trouble if you try to specify more than one y for a given set of x's. Best, David

POSTED BY: David Keith
Posted 8 years ago

Hi David,

This solves my problem indeed. You saved my day. Thanks a heap.

Two remarks, if I may: 1. I saw that both the list format {x1,x2, . . . y} as well as {{x1,x2, . . }, y} work in this case. (The Mathematica documentation recommends the latter format). 2. I would find it user-friendly if the Mathematica documentation for ListInterpolation would give am explicit referral to Interpolation for the case of non-grid lists. That would save other users a lot of heart ache.

Thanks so much for your advice, René

POSTED BY: Rene Samson
Posted 8 years ago

Hi Rene,

You want Interpolation rather than ListInterpolation. And notice that the argument is a list of {x1,x2, . . . y}.

d = RandomReal[{0, 10}, {1000, 3}];

f = Interpolation[d];

Interpolation::udeg: Interpolation on unstructured grids is currently only supported for InterpolationOrder->1 or InterpolationOrder->All. Order will be reduced to 1. >>

Plot3D[f[x, y], {x, 0, 10}, {y, 0, 10}]

InterpolatingFunction::dmval: Input value {0.000715,0.000715} lies outside the range of data in the interpolating function. Extrapolation will be used. >>

enter image description here

POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract