Message Boards Message Boards

Use the result of a numerical solution in FindRoot

Posted 1 year ago

Hello,
I want to numerically find the parameter for which the local minimum of a function reaches a particular value. I am using the example

f[x_, a_] := x - x^2 + a/3 x^3

which shows a local minimum in x for a<1. This local minimum reached 0 (which is also the value of f[0,a] for a=3/4. The function I am really interested in is more complicated and has several variables. I first find the (absolute) minimum

min[a_] := FindMinimum[{f[x, a], x >= 0}, x][[1]]

then tried FindRoot to see when this minimum reaches 0

FindRoot[min[a] == 0, {a, 1}]
FindMinimum::nrnum

probably because it tries to use the result of a numerical solution in another numerical solution.
I would rather not use FindRoot on the derivative of f[x,a] to find the minimum because there is no (real) local minimum for some values of the parameter.
Thanks for your help.

POSTED BY: Pierre Sens
2 Replies
Posted 1 year ago

Works great. I figured it was a simple question. Thanks,

POSTED BY: Pierre Sens

Try NumericQ:

ClearAll[f, min];
f[x_, a_] := x - x^2 + a/3 x^3;
min[a_?NumericQ] := FindMinimum[{f[x, a], x >= 0}, x][[1]];
FindRoot[min[a] == 0, {a, 1}]
(*  {a -> 0.75}   *)

See https://support.wolfram.com/12502 for a discussion of ?NumericQ.

POSTED BY: Michael Rogers
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract