0
$\begingroup$

I have a function of two variables $f(x,y)$. I find the maximum value of $f(x_0,y)$ by first substituting the value of $x=x_0$ and then maximizing in the range $0<y<1$.

My question is: How to plot a function with first substituting a value of $x=x_0$ and then getting out a value fromFindMaximum for a range of values $1<x_0<2$?

MWE:

f[x_] := (x + y)^2;
Plot[FindMaximum[{f[x], 0 < y < 1}, y], {x, 1, 2}]
$\endgroup$
0
$\begingroup$
f[x_] := (x + y)^2;
obj[x_?NumericQ] := First@FindMaximum[{f[x], 0 < y < 1}, y];
Plot[obj[x], {x, 0, 2}]

enter image description here

Or you could use

obj[x_?NumericQ] := FindMaxValue[{f[x], 0 < y < 1}, y]
$\endgroup$
  • $\begingroup$ Thank you. What would be the obj function if my function has three variables? f(x0,y0,z)? $\endgroup$ – kaka Oct 6 at 19:44
  • 1
    $\begingroup$ @kaka You're welcome. I suppose it would likely be obj[x0_?NumericQ, y0_?NumericQ, z_?NumericQ] := f[x0, y0, z], but it could depend on the details of the function and its use. $\endgroup$ – Michael E2 Oct 6 at 19:51

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.