0
$\begingroup$

I have a function in table form (x vs y):

data={{0., 260.}, {0.00355759, 259.999}, {0.00711519, 259.999}, {0.0106728,
   145.082}, {0.0142304, 109.453}, {0.017788, 101.983}, {0.0213456, 
  100.415}, {0.0249031, 100.088}, {0.0284607, 100.02}, {0.0320183, 
  100.005}, {0.0355759, 100.001}, {0.0391335, 100.}, {0.0426911, 
  100.}, {0.0462487, 100.}, {0.0498063, 99.9999}, {0.0533639, 
  99.9999}, {0.0569215, 99.9999}, {0.0604791, 99.9999}, {0.0640367, 
  99.9999}, {0.0675943, 99.9999}, {0.0711519, 99.9999}, {0.0747094, 
  99.9999}, {0.078267, 99.9999}, {0.0818246, 99.9999}, {0.0853822, 
  99.9999}, {0.0889398, 99.9999}, {0.0924974, 99.9999}, {0.096055, 
  99.9999}, {0.0996126, 99.9999}, {0.10317, 99.9999}, {0.106728, 
  99.9999}, {0.110285, 99.9999}, {0.113843, 99.9999}, {0.117401, 
  99.9999}, {0.120958, 99.9999}, {0.124516, 99.9999}, {0.128073, 
  99.9999}, {0.131631, 99.9999}, {0.135189, 99.9999}, {0.138746, 
  99.9999}, {0.142304, 99.9999}, {0.145861, 99.9999}, {0.149419, 
  99.9999}, {0.152976, 99.9999}, {0.156534, 99.9999}, {0.160092, 
  99.9999}, {0.163649, 99.9999}, {0.167207, 99.9999}, {0.170764, 
  99.9999}, {0.174322, 99.9999}, {0.17788, 99.9999}, {0.181437, 
  99.9999}, {0.184995, 99.9999}, {0.188552, 99.9999}, {0.19211, 
  99.9999}, {0.195668, 99.9999}, {0.199225, 99.9999}, {0.202783, 
  99.9999}, {0.20634, 99.9999}, {0.209898, 99.9999}, {0.213456, 
  99.9999}, {0.217013, 99.9999}, {0.220571, 99.9999}, {0.224128, 
  99.9999}, {0.227686, 99.9999}, {0.231244, 99.9999}, {0.234801, 
  99.9999}, {0.238359, 99.9999}, {0.241916, 99.9999}, {0.245474, 
  99.9999}, {0.249031, 99.9999}, {0.252589, 99.9999}, {0.256147, 
  99.9999}, {0.259704, 99.9999}, {0.263262, 99.9999}, {0.266819, 
  99.9999}, {0.270377, 99.9999}, {0.273935, 99.9999}, {0.277492, 
  99.9999}, {0.28105, 99.9999}, {0.284607, 99.9999}, {0.288165, 
  99.9999}, {0.291723, 99.9999}, {0.29528, 99.9999}, {0.298838, 
  99.9999}, {0.302395, 99.9999}, {0.305953, 99.9999}, {0.309511, 
  99.9999}, {0.313068, 99.9999}, {0.316626, 99.9999}, {0.320183, 
  99.9999}, {0.323741, 99.9999}, {0.327299, 99.9999}, {0.330856, 
  99.9999}, {0.334414, 99.9999}, {0.337971, 99.9999}, {0.341529, 
  99.9999}, {0.345086, 99.9999}, {0.348644, 99.9999}, {0.352202, 
  99.9999}, {0.355759, 99.9999}, {0.359317, 99.9999}, {0.362874, 
  99.9999}, {0.366432, 99.9999}, {0.36999, 99.9999}, {0.373547, 
  99.9999}, {0.377105, 99.9999}, {0.380662, 99.9999}, {0.38422, 
  99.9999}, {0.387778, 99.9999}, {0.391335, 99.9999}, {0.394893, 
  99.9999}, {0.39845, 99.9999}, {0.402008, 99.9999}, {0.405566, 
  99.9999}, {0.409123, 99.9999}, {0.412681, 99.9999}, {0.416238, 
  99.9999}, {0.419796, 99.9999}, {0.423354, 99.9999}, {0.426911, 
  99.9999}, {0.430469, 99.9999}, {0.434026, 99.9999}, {0.437584, 
  99.9999}, {0.441141, 99.9999}, {0.444699, 99.9999}, {0.448257, 
  99.9999}, {0.451814, 99.9999}, {0.455372, 99.9999}, {0.458929, 
  99.9999}, {0.462487, 99.9999}, {0.466045, 99.9999}, {0.469602, 
  99.9999}, {0.47316, 99.9999}, {0.476717, 99.9999}, {0.480275, 
  99.9999}, {0.483833, 99.9999}, {0.48739, 99.9999}, {0.490948, 
  99.9999}, {0.494505, 99.9999}, {0.498063, 99.9999}, {0.501621, 
  99.9999}, {0.505178, 99.9999}, {0.508736, 99.9999}, {0.512293, 
  99.9999}, {0.515851, 99.9999}, {0.519409, 99.9999}, {0.522966, 
  99.9999}, {0.526524, 99.9999}, {0.530081, 99.9999}, {0.533639, 
  99.9999}, {0.537196, 99.9999}, {0.540754, 99.9999}, {0.544312, 
  99.9999}, {0.547869, 99.9999}, {0.551427, 99.9999}, {0.554984, 
  99.9999}, {0.558542, 99.9999}, {0.5621, 99.9999}, {0.565657, 
  99.9999}, {0.569215, 99.9999}, {0.572772, 99.9999}, {0.57633, 
  99.9999}, {0.579888, 99.9999}, {0.583445, 99.9999}, {0.587003, 
  99.9999}, {0.59056, 99.9999}, {0.594118, 99.9999}, {0.597676, 
  99.9999}, {0.601233, 99.9999}, {0.604791, 99.9999}, {0.608348, 
  99.9999}, {0.611906, 99.9999}, {0.615464, 99.9999}, {0.619021, 
  99.9999}, {0.622579, 99.9999}, {0.626136, 99.9999}, {0.629694, 
  99.9999}, {0.633251, 99.9999}, {0.636809, 99.9999}, {0.640367, 
  99.9999}, {0.643924, 99.9999}, {0.647482, 99.9999}, {0.651039, 
  99.9999}, {0.654597, 99.9999}, {0.658155, 99.9999}, {0.661712, 
  99.9999}, {0.66527, 99.9999}, {0.668827, 99.9999}, {0.672385, 
  99.9999}, {0.675943, 99.9999}, {0.6795, 99.9999}, {0.683058, 
  99.9999}, {0.686615, 99.9999}, {0.690173, 99.9999}, {0.693731, 
  99.9999}, {0.697288, 99.9999}, {0.700846, 99.9999}, {0.704403, 
  99.9999}, {0.707961, 99.9999}, {0.711519, 99.9999}, {0.715076, 
  99.9999}, {0.718634, 99.9999}, {0.722191, 99.9999}, {0.725749, 
  99.9999}, {0.729306, 99.9999}, {0.732864, 99.9999}, {0.736422, 
  99.9999}, {0.739979, 99.9999}, {0.743537, 99.9999}, {0.747094, 
  99.9999}, {0.750652, 99.9999}, {0.75421, 99.9999}, {0.757767, 
  99.9999}, {0.761325, 99.9999}, {0.764882, 99.9999}, {0.76844, 
  99.9999}, {0.771998, 99.9999}, {0.775555, 99.9999}, {0.779113, 
  99.9999}, {0.78267, 99.9999}, {0.786228, 99.9999}, {0.789786, 
  99.9999}, {0.793343, 99.9999}, {0.796901, 99.9997}, {0.800458, 
  99.9995}, {0.804016, 99.9993}, {0.807574, 99.9991}, {0.811131, 
  99.9989}, {0.814689, 99.9987}, {0.818246, 99.9984}, {0.821804, 
  99.9982}, {0.825361, 99.998}, {0.828919, 99.9978}, {0.832477, 
  99.9976}, {0.836034, 99.9974}, {0.839592, 99.9972}, {0.843149, 
  99.997}, {0.846707, 99.9968}, {0.850265, 99.9965}, {0.853822, 
  99.9963}, {0.85738, 99.9961}, {0.860937, 99.9959}, {0.864495, 
  99.9957}, {0.868053, 99.9955}, {0.87161, 99.9953}, {0.875168, 
  99.9951}, {0.878725, 99.9948}, {0.882283, 99.9946}, {0.885841, 
  99.9944}, {0.889398, 99.9942}, {0.892956, 99.994}, {0.896513, 
  46.2395}, {0.900071, 33.4084}, {0.903629, 30.7159}, {0.907186, 
  30.1504}, {0.910744, 30.0323}, {0.914301, 30.007}, {0.917859, 
  30.0015}, {0.921416, 30.0002}, {0.924974, 29.9999}, {0.928532, 
  29.9998}, {0.932089, 30.}, {0.935647, 30.}, {0.939204, 
  30.}, {0.942762, 30.}, {0.94632, 30.}, {0.949877, 30.}, {0.953435, 
  30.}, {0.956992, 30.}, {0.96055, 30.}, {0.964108, 30.}, {0.967665, 
  30.}, {0.971223, 30.}, {0.97478, 30.}, {0.978338, 30.}, {0.981896, 
  30.}, {0.985453, 30.}, {0.989011, 30.}, {0.992568, 30.}, {0.996126, 
  30.}, {0.999684, 30.}, {1.00324, 30.}, {1.0068, 30.}, {1.01036, 
  30.}, {1.01391, 30.}, {1.01747, 30.}, {1.02103, 30.}, {1.02459, 
  30.}, {1.02814, 30.}, {1.0317, 30.}, {1.03526, 30.}, {1.03882, 
  30.}, {1.04237, 30.}, {1.04593, 30.}, {1.04949, 30.}, {1.05305, 
  30.}, {1.05661, 30.}, {1.06016, 30.}, {1.06372, 30.}, {1.06728, 
  30.}, {1.07084, 30.}, {1.07439, 30.}, {1.07795, 30.}, {1.08151, 
  30.}, {1.08507, 30.}, {1.08862, 30.}, {1.09218, 30.}, {1.09574, 
  30.}, {1.0993, 30.}, {1.10285, 30.}, {1.10641, 30.}, {1.10997, 
  30.}, {1.11353, 30.}, {1.11708, 30.}, {1.12064, 30.}, {1.1242, 
  30.}, {1.12776, 30.}, {1.13131, 30.}, {1.13487, 30.}, {1.13843, 
  30.}, {1.14199, 30.}, {1.14554, 30.}, {1.1491, 30.}, {1.15266, 
  30.}, {1.15622, 30.}, {1.15978, 30.}, {1.16333, 30.}, {1.16689, 
  30.}, {1.17045, 30.}, {1.17401, 30.}, {1.17756, 30.}, {1.18112, 
  30.}, {1.18468, 30.}, {1.18824, 30.}, {1.19179, 30.}, {1.19535, 
  30.}, {1.19891, 30.}, {1.20247, 30.}, {1.20602, 30.}, {1.20958, 
  30.}, {1.21314, 30.}, {1.2167, 30.}, {1.22025, 30.}, {1.22381, 
  30.}, {1.22737, 30.}, {1.23093, 30.}, {1.23448, 30.}, {1.23804, 
  30.}, {1.2416, 30.}, {1.24516, 30.}, {1.24872, 30.}, {1.25227, 
  30.}, {1.25583, 30.}, {1.25939, 30.}, {1.26295, 30.}, {1.2665, 
  30.}, {1.27006, 30.}, {1.27362, 30.}, {1.27718, 30.}, {1.28073, 
  30.}, {1.28429, 30.}, {1.28785, 30.}, {1.29141, 30.}, {1.29496, 
  30.}, {1.29852, 30.}, {1.30208, 30.}, {1.30564, 30.}, {1.30919, 
  30.}, {1.31275, 30.}, {1.31631, 30.}, {1.31987, 30.}, {1.32342, 
  30.}, {1.32698, 30.}, {1.33054, 30.}, {1.3341, 30.}, {1.33765, 
  30.}, {1.34121, 30.}, {1.34477, 30.}, {1.34833, 30.}, {1.35189, 
  30.}, {1.35544, 30.}, {1.359, 30.}, {1.36256, 30.}, {1.36612, 30.}, 
 {1.36967, 30.}, {1.37323, 30.}, {1.37679, 30.}, {1.38035, 
  30.}, {1.3839, 30.}, {1.38746, 30.}, {1.39102, 30.}, {1.39458, 
  30.}, {1.39813, 30.}, {1.40169, 30.}, {1.40525, 30.}, {1.40881, 
  30.}, {1.41236, 30.}, {1.41592, 30.}, {1.41948, 30.}, {1.42304, 
  30.}, {1.42659, 30.}, {1.43015, 30.}, {1.43371, 30.}, {1.43727, 
  30.}, {1.44083, 30.}, {1.44438, 30.}, {1.44794, 30.}, {1.4515, 
  30.}, {1.45506, 30.}, {1.45861, 30.}, {1.46217, 30.}, {1.46573, 
  30.}, {1.46929, 30.}, {1.47284, 30.}, {1.4764, 30.}, {1.47996, 
  30.}, {1.48352, 30.}, {1.48707, 30.}, {1.49063, 30.}, {1.49419, 
  30.}, {1.49775, 30.}, {1.5013, 30.}, {1.50486, 30.}, {1.50842, 
  30.}, {1.51198, 30.}, {1.51553, 30.}, {1.51909, 30.}, {1.52265, 
  30.}, {1.52621, 30.}, {1.52976, 30.}, {1.53332, 30.}, {1.53688, 
  30.}, {1.54044, 30.}, {1.544, 30.}, {1.54755, 30.}, {1.55111, 
  30.}, {1.55467, 30.}, {1.55823, 30.}, {1.56178, 30.}, {1.56534, 
  30.}, {1.5689, 30.}, {1.57246, 30.}, {1.57601, 30.}, {1.57957, 
  30.}, {1.58313, 30.}, {1.58669, 30.}, {1.59024, 30.}, {1.5938, 
  30.}, {1.59736, 30.}, {1.60092, 30.}, {1.60447, 30.}, {1.60803, 
  30.}, {1.61159, 30.}, {1.61515, 30.}, {1.6187, 30.}, {1.62226, 
  30.}, {1.62582, 30.}, {1.62938, 30.}, {1.63294, 30.}, {1.63649, 
  30.}, {1.64005, 30.}, {1.64361, 30.}, {1.64717, 30.}, {1.65072, 
  30.}, {1.65428, 30.}, {1.65784, 30.}, {1.6614, 30.}, {1.66495, 
  30.}, {1.66851, 30.}, {1.67207, 30.}, {1.67563, 30.}, {1.67918, 
  30.}, {1.68274, 30.}, {1.6863, 30.}, {1.68986, 29.9999}, {1.69341, 
  29.9999}, {1.69697, 29.9999}, {1.70053, 29.9999}, {1.70409, 
  29.9999}, {1.70764, 29.9999}, {1.7112, 29.9999}, {1.71476, 
  29.9999}, {1.71832, 29.9998}, {1.72187, 29.9998}, {1.72543, 
  29.9998}, {1.72899, 29.9998}, {1.73255, 29.9998}, {1.73611, 
  29.9998}, {1.73966, 29.9998}, {1.74322, 29.9997}, {1.74678, 
  29.9997}, {1.75034, 29.9997}, {1.75389, 29.9997}, {1.75745, 
  29.9997}, {1.76101, 29.9997}, {1.76457, 29.9997}, {1.76812, 
  29.9997}, {1.77168, 29.9996}, {1.77524, 29.9996}, {1.7788, 0}}

By plotting it with a log abscissa axis, it becomes obvious that this function changes steeply at two x-values. I would like to calculate the first derivative of this functions (g[x]). Therefore, as often, I did:

dataInt = Interpolation[data];
g[x_] = D[dataInt[x], {x, 1}];

Nevertheless, the function g[x] when plotted on a Log-Log plane shows a lot of 'breaks' that are of numerical origin. How to get rid of them and do this properly?

$\endgroup$
1
  • $\begingroup$ Is your function correct. It looks rather like a step function than a smooth function. $\endgroup$ May 15 at 10:59

1 Answer 1

1
$\begingroup$

I do not see how your data is "smooth" when plotted on a logarithmic x-axis, but I can help with the derivative.

$Version
"13.0.0 for Microsoft Windows (64-bit) (December 3, 2021)"

When using Interpolation you have to critically question your choices. Without any specified options, Interpolation tries to fit all your given data. This may lead to undesirable artifacts, as in this example:

interpoldata = Interpolation[data];
Show[ListPlot[data, PlotStyle -> {Thick, Red}], 
 Plot[interpoldata[x], {x, 0, 1.7788}]]

Gives:

enter image description here

Notice the spikes in the Interpolation function? When you build your derivative of this function, you will get a positive slope where there is none in your data. This can be remedied by setting InterpolationOrder->1, giving you linear interpolation between your data points:

interpoldata = Interpolation[data, InterpolationOrder -> 1];
Show[ListPlot[data, PlotStyle -> {Thick, Red}], 
 Plot[interpoldata[x], {x, 0, 1.7788}]]

Gives:

enter image description here

And with appropriate settings for Interpolation you easily get the derivative:

interpoldata = Interpolation[data, InterpolationOrder -> 1];
Plot[interpoldata'[x], {x, 0, 1.7788}, PlotRange -> All]

enter image description here

$\endgroup$
3
  • $\begingroup$ thanks for the answer. what I meant with 'smooth' is actually 'without spikes'. Setting InterpolationOrder to 1 does help. However, if I plot your solution using LogLogPlot, I still see a lot of spikes. $\endgroup$
    – Luigi
    May 15 at 12:52
  • $\begingroup$ It is certainly possible that I do not fully understand the question you are asking then. Maybe you should clarify in your opening post. $\endgroup$
    – rowsi
    May 15 at 18:34
  • $\begingroup$ Is it clear now? $\endgroup$
    – Luigi
    May 16 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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