0

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}]
kaka
  • 351
  • 2
  • 11

1 Answers1

0
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]
Michael E2
  • 235,386
  • 17
  • 334
  • 747
  • Thank you. What would be the obj function if my function has three variables? f(x0,y0,z)? – kaka Oct 06 '19 at 19:44
  • 1
    @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. – Michael E2 Oct 06 '19 at 19:51