0
$\begingroup$

enter image description here

I am facing some issues with performing an interpolation. From the image, you can find the values in three columns, the 1st column is x, the second column is y and the third column is F. I want to find a function, F(x, y) with Interpolation. But the interpolation is not working correctly. Most of the time, I get negative or wrong values if the input value lies outside the range of data in the interpolating function. This is the link of my data file.

Here is what I tried:

data1 = Import["source.dat", "Table"]; (*I stored the data in .dat file*)
x = data1[[All, 1]]; y = data1[[All, 2]]; F = data1[[All, 3]]; (*Assigning the value of x, y, F*)

F1 = Interpolation[Transpose[{x, y, F}], InterpolationOrder -> 1]; (*Interpolation*) 

F2[x_?NumericQ, y_?NumericQ] := F1[x, y]; (*wrote it as a function of x and y as later I will use it for another purpose*)

I have tried to change the InterpolationOrder -> 1 to All, but it does not solve the issue. Most of the time I get wrong values from interpolation. I am calling interpolation with F1[x, y]. Help me with ideas to solve the issue. I am using Mathematica v12 and v13.

$\endgroup$
7
  • 2
    $\begingroup$ "I get negative or wrong values if the input value lies outside the range of data in the interpolating function" <- this is your problem. Interpolation gives you a function that works only on a specific domain. $\endgroup$
    – lericr
    Aug 1, 2023 at 20:57
  • 1
    $\begingroup$ "Most of the time I am getting the wrong values from interpolation." Maybe you can provide specific inputs that are giving you wrong results (and why you think the results are wrong). $\endgroup$
    – lericr
    Aug 1, 2023 at 20:57
  • $\begingroup$ @lericr For example, F1[0.1, 10^-30], I am getting the value "-4.61896*10^38" with this warning message, "Input value lies outside the range of data in the interpolating function.". I am not supposed to get any negative value. $\endgroup$ Aug 1, 2023 at 21:04
  • 1
    $\begingroup$ Well, 10^-30 is outside of the range of data for the y values. Like the warning message says. $\endgroup$
    – lericr
    Aug 1, 2023 at 21:07
  • 1
    $\begingroup$ Hmm. Looking at the shape of your data, I'm not really sure what Interpolation should be expected to do. To my eye, that point does look problematic, but I'm not really sure what Interpolation is actually doing with the data you gave it. $\endgroup$
    – lericr
    Aug 1, 2023 at 23:05

1 Answer 1

1
$\begingroup$

You won't have much luck attempting to use interpolation using both $X$ and $Y$ with any software package. Here is a plot of your data:

data1 = Import["source.dat", "Table"];
data1 = data1[[2 ;;]];
ListPointPlot3D[data1, SphericalRegion -> True, RotationAction -> "Clip",
  AxesLabel -> (Style[#, 18, Bold, Black] &) /@ {"X", "Y", "F"}, ImagePadding -> 50]

3D plot of data

Given that for a given $X$ there is only small range of values of $Y$ and for a given $Y$ there is only a small range of values of $X$, one should not expect justifiable results from most of the possible $(X,Y)$. In short, there's only data available for a small subset of $X$ and $Y$ values.

$\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.