1
$\begingroup$

I Have the problem with the maximize of this problem:

ClearAll[expr, max, sol, x, y];
expr = (1 + x + y)/((1 + x + y) + 1)* 10 - 
   y - (((1 + x)/((1 + x) + 1))*10);

max = Simplify[Maximize[{expr, 0 <= y <= 1.5, 0 <= x <= 0.5}, y]]

What it returned is:

Maximize[{-((y (x^2 + 2 (-3 + y) + x (4 + y)))/((2 + x) (2 + x + y))),
   0 <= y <= 1.5, 0 <= x <= 0.5}, y]

So it did not work.

I have another question with regard to extraction of value when use maximize function. After using Maximize, how do I extract the value of y and the value of the maximum function? y/. did not seem to work

My final question is regard to lower bound of a function. For example, my function is this

(1 + x + y)/((1 + x + y) + 1)* 10 - y - (((1 + x)/((1 + x) + 1))*10);

I want to create a code, such that for the above function, when x runs from 0 to 1, we find the maximum of that, expressed in terms of x. However, if the function is lower than 0, I want to return 0 and y is equal 0 in such case.

Thank you all so much!

$\endgroup$
0

2 Answers 2

1
$\begingroup$
Clear["Global`*"]

expr = (1 + x + y)/((1 + x + y) + 1)*10 - y - (((1 + x)/((1 + x) + 1))*10);

Use exact numbers and use the constraints as Assumptions in Simplify

maxX = Simplify[
  Maximize[{expr, 0 <= y <= 3/2, 0 <= x <= 1/2}, x], {0 <= y <= 3/2, 
   0 <= x <= 1/2}]

(* {-(((-3 + y)*y)/(2 + y)), 
   {x -> Piecewise[{{1/4, y == 0}}, 0]}} *)

EDIT: Use Part to verify that the max value (maxX[[1]]) is produced by evaluating expr at the specified value of x (maxX[[2]]),

Assuming[{0 <= y <= 3/2, 0 <= x <= 1/2},
 maxX[[1]] == expr /. maxX[[2]] // Simplify]

(* True *)

maxXY = Maximize[{expr, 0 <= y <= 3/2, 0 <= x <= 1/2}, {x, y}] //
  Simplify

(* {7 - 2 Sqrt[10], {x -> 0, y -> -2 + Sqrt[10]}} *)

maxXY // N

(* {0.675445, {x -> 0., y -> 1.16228}} *)

EDIT: Again, using Part to verify,

maxXY[[1]] == expr /. maxXY[[2]]

(* True *)
$\endgroup$
0
$\begingroup$

Your expression has two variables, so

max = Simplify[Maximize[{expr, 0 <= y <= 1.5, 0 <= x <= 0.5}, {x, y}]]

{0.675445, {x -> 0., y -> 1.16228}}

The maximum value is then

max[[1]]

0.675445

And the x and y values are

{x, y} /. max[[2]]

{0., 1.16228}

Update

Maybe something like this:

Your expression looks well-behaved

Plot3D[expr, {x, 0, .5}, {y, 0, 1.5}, AxesLabel -> {x, y}]

enter image description here

So we could see where the derivative with respect to y is 0

sol = Solve[D[expr, y] == 0, y]
(* {{y -> -2 - Sqrt[10] - x}, {y -> -2 + Sqrt[10] - x}} *)

Plot[y /. sol[[2]], {x, 0, .5}, AxesLabel -> {"x", "maxy"}]

enter image description here

Alternatively,

maxy[xx_] := 
 Maximize[{expr, 0 <= y <= 1.5, 0 <= x <= 0.5} /. x -> xx, y]

Plot[y /. maxy[x][[2]], {x, 0, .5}]

enter image description here

$\endgroup$
3
  • $\begingroup$ that's not what I meant, I need to find maximum of function with regard to x (in economics its called value function, if you do economics) $\endgroup$
    – user66418
    Commented Sep 1, 2019 at 21:39
  • $\begingroup$ @user66418 See if the answer update is more helpful $\endgroup$
    – MelaGo
    Commented Sep 1, 2019 at 22:08
  • $\begingroup$ Hi, thank you for your help, I asked my colleagues and they say Nsolve may miss some maximum value. Do you have anyother suggestions? Thank you so much $\endgroup$
    – user66418
    Commented Sep 8, 2019 at 20:05

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.