1
$\begingroup$

I'm trying to find maximum of the functions that I created by interpolating experimental data by using FindMaximum:

FindMaximum[{ii[x]}, {x, 41, 40, 57}, Method -> InteriorPoint]

but it works not very stable way. Here is the results of application of this function to 9 different curves. As you can see in the last curve it failed to find maximum, while the curve itself looks similar to others:

enter image description here

Any ideas why it happens and how I can fix it?

$\endgroup$
2
  • 1
    $\begingroup$ It looks like you're looking for a point ii'[x]==0? If yes try NSolve[ii'[x]==0&&ii''[x]<0,40<x<60,x] $\endgroup$ Commented May 26, 2023 at 12:16
  • 2
    $\begingroup$ If you provide no complete code and no data, we can provide no help... $\endgroup$
    – MarcoB
    Commented May 26, 2023 at 16:21

1 Answer 1

2
$\begingroup$

FindMaximum searches for a local maximum. FindMaximum is working properly in your last example, it can find the global max in the bound value of your function. So, FindMaximum is working ok.

However, it looks like you're looking for points where your function has a local max.

For example, if your function is $\dfrac{\sin(10\pi x^{3})}{2x} + (x-1/2)^{4}$ and your range to search for the optimal values are from -1.3 to 1.3:

f = Sin[10 Pi x^3]/(2 x) + (x - 1/2)^4;
xLimits = {-1.3, 1.3};

You can use WhenEvent and NDSolve to find the points where f'[x] == 0:

{sol, points} = 
  Reap@NDSolve[{y'[x] == D[f, x], 
     y[xLimits[[1]]] == (f /. x -> xLimits[[1]]), 
     WhenEvent[y'[x] == 0, Sow[{x, y[x]}]]}, 
    y[x], {x, xLimits[[1]], xLimits[[2]]}];

Plot the results:

Plot[f, {x, xLimits[[1]], xLimits[[2]]}, 
 Epilog -> {PointSize[Medium], Red, Point[Flatten[points, 1]]}, 
 PlotPoints -> 20]

Find all local max/min

You can do something similar if you want only the max local values.

points = Select[Flatten[points, 1], (D[f, {x, 2}] /. x -> #[[1]]) < 0 &];
Plot[f, {x, xLimits[[1]], xLimits[[2]]}, 
 Epilog -> {PointSize[Medium], Red, Point[points]}, PlotPoints -> 20]

Local max 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.