You can do a search for extrema (differential calculus), on the interpolated version of your dataset. See how to get an interpolated function from a set of data points here. The simplest way (assuming you have polynomial data) is to do a polynomial fit over points
:
points = {
{-5., 365.}, {-4.951, 356.571}, {-4.804, 331.998}, {-1.888, 38.604},
{-0.018, -0.033}, {2.565, 54.056}, {3.285, 79.016}, {6.3, 159.451},
{6.459, 160.646}, {6.715, 161.555}, {6.839, 161.524}, {7.06, 160.659},
{8.971, 100.783}, {10.901, -85.324}, {15., -1095.}
}; (* points sampled from -x^3 + 10 x^2 + 2 x *)
fit = Fit[points, {1, x, x^2, x^3}, x];
f = Function[{x}, Evaluate@fit]
f[x]
0.00401351 + 2.00137 x + 9.99945 x^2 - 0.999973 x^3
Afterwards, you can get the derivative of your curve, f
. The function f
is our fitted polynomial function:
Plot[{f[x], f'[x], f''[x]}, {x, -5, 15}]
Where the first derivative is zero the function has a stationary point:
sol = NSolve[{f'[x] == 0}, x, Reals]
{{x -> -0.0986535}, {x -> 6.76506}}
Checking the second derivative tells whether at the given point of interest f
has a minimum or maximum (or f[x]
is an inflection point):
f''[x] /. sol
{20.5912, -20.5912}
where:
- $f^{\prime\prime}(x) < 0$ -> $f$ has a local maximum at $x$.
- $f^{\prime\prime}(x) > 0$ -> $f$ has a local minimum at $x$.
- $f^{\prime\prime}(x) = 0$ -> $f$ has an inflection point at $x$
Thus:
minmax = MapThread[# ->
Which[#2 < 0, "max", #2 > 0, "min", True, "inflection"] &, {x /.
sol, f''[x] /. sol}]
{-0.0986535 -> "min", 6.76506 -> "max"}
Plot[{f[x], f'[x]}, {x, -5, 15},
Epilog -> {AbsolutePointSize@5, Red,
Point[{#, f[#]} & /@ (x /. sol)], Black,
Text[Last@#, {First@#, f@First@#}, {-1, 1}] & /@ minmax}]
Abs
is incorrect. Is there a reason to include them? $\endgroup$