0
$\begingroup$

I am trying to find a proper matching function for the following data set:

xyzValues = Import["nC_Q4.csv", "Data"][[8 ;;, {6, 9, 38}]]

{{0, 0, 2.0004}, {0, 100, 0}, {0, 40, 0}, {0, 140, 0}, {0, 60, 0}, {0,
   80, 0}, {0, 120, 0}, {0, 20, 0}, {0, 160, 0}, {0, 180, 0}, {0, 240,
   0}, {0, 220, 0}, {0, 200, 0}, {0, 260, 0}, {0, 280, 0}, {0, 300, 
  0}, {0, 320, 0}, {0, 340, 0}, {0, 360, 0}, {0, 400, 0}, {0, 380, 
  0}, {0, 440, 0}, {0, 420, 0}, {0, 460, 0}, {5, 0, 1.1607}, {5, 20, 
  0}, {5, 40, 0}, {5, 60, 0}, {5, 80, 0}, {5, 100, 0}, {0, 480, 
  0}, {0, 500, 0}, {5, 120, 0}, {5, 140, 0}, {5, 160, 0}, {5, 180, 
  0}, {5, 200, 0}, {5, 240, 0}, {5, 220, 0}, {5, 260, 0}, {5, 280, 
  0}, {5, 300, 0}, {5, 320, 0}, {5, 340, 0}, {5, 360, 0}, {5, 380, 
  0}, {5, 400, 0}, {5, 420, 0}, {10, 20, 0}, {5, 440, 0}, {10, 0, 
  0.480288}, {5, 460, 0}, {10, 60, 0}, {5, 480, 0}, {5, 500, 0}, {10, 
  40, 0}, {10, 80, 0}, {10, 100, 0}, {10, 120, 0}, {10, 140, 0}, {10, 
  160, 0}, {10, 180, 0}, {10, 200, 0}, {10, 220, 0}, {10, 240, 
  0}, {10, 260, 0}, {10, 280, 0}, {10, 300, 0}, {10, 320, 0}, {10, 
  340, 0}, {10, 360, 0}, {10, 380, 0}, {10, 400, 0}, {10, 420, 
  0}, {10, 460, 0}, {10, 480, 0}, {10, 440, 0}, {15, 0, 0.5003}, {10, 
  500, 0}, {15, 20, 0}, {15, 40, 0}, {15, 60, 0}, {15, 100, 0}, {15, 
  80, 0}, {15, 120, 0}, {15, 140, 0}, {15, 160, 0}, {15, 180, 0}, {15,
   200, 0}, {15, 220, 0}, {15, 240, 0}, {15, 260, 0}, {15, 280, 
  0}, {15, 300, 0}, {15, 320, 0}, {15, 340, 0}, {15, 360, 0}, {15, 
  380, 0}, {15, 400, 0}, {15, 420, 0}, {15, 460, 0}, {15, 440, 
  0}, {15, 480, 0}, {15, 500, 0}, {20, 0, 0.520104}, {20, 20, 0}, {20,
   40, 0}, {20, 60, 0}, {20, 80, 0}, {20, 100, 0}, {20, 120, 0}, {20, 
  140, 0}, {20, 160, 0}, {20, 180, 0}, {20, 200, 0}, {20, 220, 
  0}, {20, 240, 0}, {20, 260, 0}, {20, 280, 0}, {20, 300, 0}, {20, 
  320, 0}, {20, 340, 0}, {20, 360, 0}, {20, 380, 0}, {20, 400, 
  0}, {20, 420, 0}, {20, 440, 0}, {20, 460, 0}, {20, 480, 0}, {20, 
  500, 0}, {25, 0, 0.980392}, {25, 20, 0}, {25, 40, 0}, {25, 80, 
  0}, {25, 60, 0}, {25, 100, 0}, {25, 120, 0}, {25, 140, 0}, {25, 160,
   0}, {25, 180, 0}, {25, 200, 0}, {25, 220, 0}, {25, 240, 0}, {25, 
  260, 0}, {25, 280, 0}, {25, 300, 0}, {25, 320, 0}, {25, 340, 
  0}, {25, 360, 0}, {25, 380, 0}, {25, 400, 0}, {25, 420, 0}, {25, 
  440, 0}, {25, 480, 0}, {25, 460, 0}, {25, 500, 0}, {30, 0, 
  2.36047}, {30, 20, 0}, {30, 40, 0}, {30, 60, 0}, {30, 80, 0}, {30, 
  100, 0}, {30, 120, 0}, {30, 140, 0}, {30, 160, 0}, {30, 180, 
  0}, {30, 200, 0}, {30, 220, 0}, {30, 240, 0}, {30, 260, 0}, {30, 
  280, 0}, {30, 300, 0}, {30, 320, 0}, {30, 340, 0}, {30, 360, 
  0}, {30, 380, 0}, {30, 400, 0}, {30, 420, 0}, {30, 440, 0}, {30, 
  460, 0}, {30, 480, 0}, {30, 500, 0}, {35, 0, 14.943}, {35, 20, 
  0}, {35, 40, 0}, {35, 60, 0}, {35, 80, 0}, {35, 100, 0}, {35, 120, 
  0}, {35, 140, 0}, {35, 160, 0}, {35, 180, 0}, {35, 200, 0}, {35, 
  220, 0}, {35, 240, 0}, {35, 260, 0}, {35, 280, 0}, {35, 300, 
  0}, {35, 320, 0}, {35, 340, 0}, {35, 360, 0}, {35, 380, 0}, {35, 
  400, 0}, {35, 420, 0}, {35, 440, 0}, {35, 460, 0}, {35, 480, 
  0}, {35, 500, 0}, {40, 0, 28.6972}, {40, 20, 0}, {40, 40, 0}, {40, 
  60, 0}, {40, 80, 0}, {40, 100, 0}, {40, 120, 0}, {40, 140, 0}, {40, 
  160, 0}, {40, 180, 0}, {40, 200, 0}, {40, 220, 0}, {40, 240, 
  0}, {40, 260, 0}, {40, 280, 0}, {40, 320, 0}, {40, 300, 0}, {40, 
  340, 0}, {40, 360, 0}, {40, 380, 0}, {40, 400, 0}, {40, 420, 
  0}, {40, 440, 0}, {40, 460, 0}, {40, 480, 0}, {40, 500, 0}, {45, 0, 
  34.7878}, {45, 20, 0}, {45, 40, 0}, {45, 60, 0}, {45, 80, 0}, {45, 
  100, 0}, {45, 120, 0}, {45, 140, 0}, {45, 160, 0}, {45, 180, 
  0}, {45, 200, 0}, {45, 220, 0}, {45, 240, 0}, {45, 260, 0}, {45, 
  280, 0}, {45, 300, 0}, {45, 320, 0}, {45, 340, 0}, {45, 360, 
  0}, {45, 380, 0}, {45, 400, 0}, {45, 420, 0}, {45, 440, 0}, {45, 
  460, 0}, {45, 480, 0}, {45, 500, 0}, {50, 0, 39.7718}, {50, 20, 
  0}, {50, 40, 0}, {50, 60, 0}, {50, 80, 0}, {50, 100, 0}, {50, 120, 
  0}, {50, 140, 0}, {50, 160, 0}, {50, 180, 0}, {50, 200, 0}, {50, 
  220, 0}, {50, 260, 0}, {50, 240, 0}, {50, 280, 0}, {50, 300, 
  0}, {50, 320, 0}, {50, 340, 0}, {50, 360, 0}, {50, 380, 0}, {50, 
  400, 0}, {50, 420, 0}, {50, 440, 0}, {50, 460, 0}, {50, 480, 
  0}, {50, 500, 0}, {55, 0, 47.2884}, {55, 20, 0}, {55, 40, 0}, {55, 
  60, 0}, {55, 80, 0}, {55, 100, 0}, {55, 120, 0}, {55, 140, 0}, {55, 
  160, 0}, {55, 180, 0}, {55, 200, 0}, {55, 220, 0}, {55, 240, 
  0}, {55, 260, 0}, {55, 280, 0}, {55, 300, 0}, {55, 320, 0}, {55, 
  340, 0}, {55, 360, 0}, {55, 400, 0}, {55, 380, 0}, {55, 420, 
  0}, {55, 440, 0}, {55, 460, 0}, {55, 480, 0}, {55, 500, 0}, {60, 0, 
  62.3125}, {60, 20, 0.22022}, {60, 40, 0}, {60, 60, 0}, {60, 80, 
  0}, {60, 100, 0}, {60, 120, 0}, {60, 140, 0}, {60, 160, 0}, {60, 
  180, 0}, {60, 200, 0}, {60, 220, 0}, {60, 240, 0}, {60, 260, 
  0}, {60, 280, 0}, {60, 300, 0}, {60, 320, 0}, {60, 340, 0}, {60, 
  360, 0}, {60, 380, 0}, {60, 400, 0}, {60, 420, 0}, {60, 460, 
  0}, {60, 440, 0}, {60, 480, 0}, {60, 500, 0}, {65, 0, 74.2594}, {65,
   20, 0.26026}, {65, 40, 0.020016}, {65, 60, 0}, {65, 80, 0}, {65, 
  100, 0}, {65, 120, 0}, {65, 140, 0}, {65, 160, 0}, {65, 180, 
  0}, {65, 200, 0}, {65, 220, 0}, {65, 240, 0}, {65, 260, 0}, {65, 
  280, 0}, {65, 300, 0}, {65, 320, 0}, {65, 340, 0}, {65, 360, 
  0}, {65, 380, 0}, {65, 400, 0}, {65, 420, 0}, {65, 440, 0}, {65, 
  460, 0}, {65, 480, 0}, {65, 500, 0}, {70, 0, 79.4559}, {70, 20, 
  1.60128}, {70, 40, 0.0800641}, {70, 60, 0.020004}, {70, 80, 0}, {70,
   100, 0}, {70, 140, 0}, {70, 120, 0}, {70, 160, 0}, {70, 200, 
  0}, {70, 180, 0}, {70, 220, 0}, {70, 240, 0}, {70, 260, 0}, {70, 
  280, 0}, {70, 320, 0}, {70, 300, 0}, {70, 340, 0}, {70, 360, 
  0}, {70, 380, 0}, {70, 400, 0}, {70, 420, 0}, {70, 440, 0}, {70, 
  460, 0}, {70, 480, 0}, {70, 500, 0}, {75, 0, 86.9348}, {75, 20, 
  7.30146}, {75, 40, 1.96196}, {75, 60, 0.720144}, {75, 80, 
  0.46046}, {75, 100, 0.160096}, {75, 120, 0.080016}, {75, 140, 
  0.020008}, {75, 160, 0.020008}, {75, 180, 0.020012}, {75, 200, 
  0.020012}, {75, 220, 0.020012}, {75, 240, 0}, {75, 260, 0}, {75, 
  300, 0}, {75, 280, 0}, {75, 320, 0}, {75, 340, 0}, {75, 360, 
  0}, {75, 380, 0}, {75, 400, 0}, {75, 420, 0}, {75, 440, 0}, {75, 
  460, 0}, {75, 480, 0}, {75, 500, 0}, {80, 0, 91.4783}, {80, 20, 
  13.1653}, {80, 40, 7.70308}, {80, 80, 4.0208}, {80, 60, 
  5.48439}, {80, 120, 2.84114}, {80, 100, 3.22064}, {80, 140, 
  2.60104}, {80, 160, 1.80216}, {80, 180, 1.86037}, {80, 200, 
  1.36054}, {80, 220, 1.24149}, {80, 240, 1.08065}, {80, 260, 
  1.04021}, {80, 280, 0.960384}, {80, 300, 0.860861}, {80, 320, 
  1.0004}, {80, 340, 0.80016}, {80, 360, 0.720432}, {80, 380, 
  0.540432}, {80, 400, 0.480673}, {80, 420, 0.40032}, {80, 440, 
  0.20008}, {80, 480, 0.380076}, {80, 460, 0.460184}, {80, 500, 
  0.460276}, {85, 0, 94.2188}, {85, 20, 22.0332}, {85, 40, 
  12.2649}, {85, 60, 9.26371}, {85, 80, 7.78156}, {85, 100, 
  7.14572}, {85, 120, 5.84117}, {85, 140, 5.58447}, {85, 180, 
  4.90196}, {85, 160, 5.32106}, {85, 200, 4.5209}, {85, 220, 
  4.5209}, {85, 240, 4.74095}, {85, 260, 4.18167}, {85, 280, 
  3.80076}, {85, 300, 3.92392}, {85, 320, 3.72223}, {85, 340, 
  3.64073}, {85, 360, 3.38068}, {85, 380, 3.5007}, {85, 400, 
  3.36336}, {85, 420, 3.14126}, {85, 440, 3.02181}, {85, 460, 
  2.70054}, {85, 480, 3.02242}, {85, 500, 2.90174}, {90, 0, 
  95.7592}, {90, 20, 33.1333}, {90, 60, 18.1709}, {90, 40, 
  22.1689}, {90, 80, 15.8358}, {90, 100, 13.9856}, {90, 120, 
  12.7826}, {90, 140, 12.0272}, {90, 160, 10.024}, {90, 180, 
  10.8643}, {90, 200, 9.60192}, {90, 220, 8.80528}, {90, 240, 
  8.30332}, {90, 260, 8.64173}, {90, 280, 7.74465}, {90, 300, 
  7.40148}, {90, 320, 7.92317}, {90, 340, 7.48899}, {90, 360, 
  6.7427}, {90, 380, 6.82546}, {90, 400, 6.2425}, {90, 420, 
  6.76135}, {90, 440, 6.40512}, {90, 460, 6.84137}, {90, 480, 
  5.54222}, {90, 500, 6.16246}, {95, 0, 97.4795}, {95, 20, 
  42.9972}, {95, 40, 31.8191}, {95, 60, 28.6657}, {95, 80, 
  25.6903}, {95, 100, 22.8337}, {95, 120, 21.733}, {95, 140, 
  20.1201}, {95, 160, 18.6074}, {95, 180, 18.6875}, {95, 200, 
  17.3635}, {95, 220, 17.1869}, {95, 240, 16.6433}, {95, 260, 
  15.6062}, {95, 280, 15.3954}, {95, 300, 14.8118}, {95, 320, 
  15.3985}, {95, 340, 14.1657}, {95, 360, 14.9439}, {95, 380, 
  14.5229}, {95, 400, 14.0684}, {95, 420, 13.5681}, {95, 440, 
  13.4454}, {95, 460, 12.7051}, {95, 480, 13.5227}, {100, 0, 
  98.3397}, {95, 500, 13.2653}, {100, 20, 52.0416}, {100, 40, 
  43.1773}, {100, 60, 38.2153}, {100, 80, 34.9079}, {100, 100, 
  32.0328}, {100, 120, 30.5506}, {100, 140, 29.3729}, {100, 160, 
  29.0407}, {100, 180, 27.0908}, {100, 200, 26.4853}, {100, 220, 
  25.8252}, {100, 240, 25.245}, {100, 280, 24.1697}, {100, 260, 
  25.4152}, {100, 300, 25.2752}, {100, 320, 22.8646}, {100, 340, 
  23.0246}, {100, 360, 22.0888}, {100, 380, 22.2467}, {100, 400, 
  23.3247}, {100, 420, 22.9892}, {100, 440, 21.0242}, {100, 460, 
  20.9284}, {100, 480, 21.8775}, {100, 500, 19.6035}}

Which has dimensions

Dimensions[xyzValues]

{546, 3}

First, I have tried to plot these point in a contour plot:

ListContourPlot[xyzValues, PlotLegends -> Automatic, 
 ColorFunction -> "Rainbow", PlotRange -> {{0, 100}, {0, 150}}]

enter image description here

but this result does not reflect the data points (see for example there exist data in the blank zone of the plot). Probably, I am missing something, but the plot should be different. Plotting these points with another mathematical framework:

enter image description here

Observing these two plots, I do not know how to compute a good mathematical function to match these data point. I have made an approximation

model = a + b x + c x^2 + d Exp[-x] + e y + f y^2 + g x y + Exp[-y] h ;

fit = 
 FindFit[xyzValues, model, {a, b, c, d, e, f, g, h}, {x, y}]

{a -> -2.75705, b -> -0.196263, c -> 0.00570384, 
 d -> -4.9015, e -> 0.0131326, f -> 0.0000346097, g -> -0.000773403, 
 h -> 38.7327}

and plot this function:

Show[{Plot3D[Evaluate[model /. fit], {x, 0, 100}, {y, 0, 150}, 
   PlotStyle -> Opacity[0.8]], 
  Graphics3D[{Red, PointSize[.025], Map[Point, xyzValues]}]}]

enter image description here

However, it seems an approximation with much error. I would like to get a function with less error, if possible an expression that interpolates de data points.

Regards

$\endgroup$
5
  • 1
    $\begingroup$ For the ListContourPlot, use PlotRange -> {{0, 100}, {0, 150}, All} instead. (Mathematica chooses to cut off some of the z-values. $\endgroup$
    – march
    Commented Apr 16, 2019 at 16:29
  • 4
    $\begingroup$ As for fitting your data to a function, you should really only be doing something like that if the context of the data informs what the function should look like. Is there some physical context or some theory that suggests what the functional form should be? If not, then you can just create an InterpolatingFunction using Interpolation on your date. Look it up in the documentation. $\endgroup$
    – march
    Commented Apr 16, 2019 at 16:32
  • $\begingroup$ @march Thank you. The PlotRange change works fine. On the interpolation function, I would need an expression for the data. The data is a result of finding the percentage of error in an experiment varying two parameters. These data are obtained from simulation, and there is no expression known. I would appreciate it very much If anyone could make a hint about the model to use by showing the shape of the plot. $\endgroup$ Commented Apr 16, 2019 at 17:07
  • 1
    $\begingroup$ But, what I'm saying is that there's very little use in fitting data without having some theoretical basis for the fitting function. I could suggest trying a two-dimensional polynomial of degree 20, or a sum of 2D sines and cosines with 20 or 30 different frequencies, and you would likely get a very good fit, but there would also be loads of parameters, and it would be impossible to interpret what you've got. $\endgroup$
    – march
    Commented Apr 16, 2019 at 17:55
  • $\begingroup$ @march You are right. Thank you. $\endgroup$ Commented Apr 16, 2019 at 17:59

1 Answer 1

1
$\begingroup$

Instead of FindFit you could use a linear interpolating function:

f = Interpolation[{{#, #2}, #3} & @@@ xyzValues, InterpolationOrder -> 1];

cols = RGBColor @@@ ({{53, 42, 134}, {15, 91, 221}, {18, 124, 215}, {6, 156, 207}, {21, 176, 180},
             {88, 189, 139}, {165, 190, 106}, {225, 185, 82}, {251, 205, 45}, {248, 250, 13}}/255);

plot = ContourPlot[f[x, y], {x, 0, 100}, {y, 0, 100}, Contours -> Range[10, 90, 10],
  ColorFunction -> (Blend[cols, #] &), PlotRange -> All, ContourLabels -> True, ImageSize -> 600]

The positions of the labels are not too good though. The code below replaces them by labels at manually picked vertices from each contour line.

plot /. Cases[plot, __Text, All] ->
  Catenate[MapThread[Thread[Text[#2[[1]], #[[1, 13 ;; ;; 76]]]] &,
    {Cases[plot, _Line, All], Reverse[Cases[plot, _Text, All]]}]]

$\endgroup$
1
  • $\begingroup$ thank you. I am looking for an expression representing the data. Do you know any way to get the expression behind ˋ ÌnterpolatingFunctionˋ $\endgroup$ Commented Apr 17, 2019 at 14:22

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.