1
$\begingroup$

If I have g which is a list of Interpolation functions such (I cannot copy the interpolation functions for some reason):

g=enter image description here

How can I convert that to a list of data (say from 20 to 100)?. What I mean is a list of data where I could use for instance later ListPlot and I could plot it that way.

UPDATE:

I have tried Table[g, {x, 20, 100}] before but I get the following error:

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ Table[g, {x, 20, 100}]? But why not use Plot[g, {x, 20, 100}] directly though? $\endgroup$
    – MarcoB
    Jan 19 at 4:21
  • $\begingroup$ @MarcoB thanks! I have tried that but it doesn't work in my case (see update). I think is because my Interpolating functions are at different values of x in the list. $\endgroup$
    – John
    Jan 19 at 4:25
  • 2
    $\begingroup$ The domain of the first IF ends at x around 90. For x between 90 and 100, you get the error. $\endgroup$
    – Michael E2
    Jan 19 at 4:26
2
$\begingroup$
Clear["Global`*"]

data = RandomReal[10, {20, 2}] // Sort;

g = Interpolation[data]

enter image description here

The source data can be extracted from the InterpolatingFunction

data === Transpose[{g[[3, 1]], g[[4, 3]]}]

(* True *)

To uniformly resample the InterpolatingFunction on the domain

dom = g[[1, 1]]

(* {0.0472677, 9.7063} *)

data2 = {#, g[#]} & /@ (Subdivide[##, 9] & @@ dom);

Show[
 Plot[g[x], {x, dom[[1]], dom[[2]]},
  PlotRange -> All],
 ListPlot[{data, data2},
  PlotStyle -> {Blue, Red}]]

enter image description here

EDIT: Building on the comment by J.M.

g["Methods"]

(* {"Coordinates", "DerivativeOrder", "Domain", "ElementMesh", "Evaluate", \
"GetPolynomial", "Grid", "InterpolationMethod", "InterpolationOrder", \
"MethodInformation", "Methods", "OutputDimensions", "Periodicity", \
"PlottableQ", "Properties", "QuantityUnits", "Unpack", "ValuesOnGrid"} *)

The x values

(data[[All, 1]] // Sort) ===
 (g["Coordinates"] // Flatten) ===
 (g["Grid"] // Flatten)

(* True *)

The y values

Sort[data][[All, 2]] === g["ValuesOnGrid"]

(* True *)
$\endgroup$
1
  • 3
    $\begingroup$ g["Grid"] and g["ValuesOnGrid"] should work as well. $\endgroup$
    – J. M.'s torpor
    Jan 19 at 7:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.