3
$\begingroup$

I would like to obtain a function and its derivatives, where the function is defined as the solution to a maximization problem. The obvious approach

Clear[f]
f[a_?NumericQ] := NArgMax[-(x - a)^2, x]
f[1]
f'[1]

fails to give the numeric f'[1]. So I used the following:

Clear[f]
f = FunctionInterpolation[ArgMax[-(x - a)^2, x], {a, 0, 2}]
f'[1]

The actual function I would like to maximize has no closed form, thus an InterpolatingFunction object must be used:

Clear[f, g]
g = FunctionInterpolation[-(x - a)^2, {x, 0, 2}, {a, 0, 2}];
f = FunctionInterpolation[ArgMax[g[x, a], x], {a, 0, 2}]
f'[1]

This gives the error

FunctionInterpolation::nreal: Near {a} = {0}, the function did not evaluate to a real number.

How to avoid this error and get the correct f'[a] for any a?

$\endgroup$
4
$\begingroup$
Clear[f, g, gg]
g = FunctionInterpolation[-(x - a)^2, {x, 0, 2}, {a, 0, 2}];
gg[a_?NumericQ, b_?NumericQ] := g[a, b];
f = FunctionInterpolation[ArgMax[{gg[x, a], 0 <= x <= 2}, x], {a, 0, 2}]
f'[1]

(*
InterpolatingFunction[{{0.,2.}},<>]
1.
*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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