# Complex maximization problem

i would like to solve the following system:

c[e_] := 1/2*e + 1;
d[y_, x_] := x*y^2;

e[y_] := NMinimize[{Integrate[PDF[BetaDistribution[2, e], x]*d[y, x] + c[e]
, {x, 0, 1}], e >= 0}, e]

U[z_, y_, p_] := p - Integrate[PDF[BetaDistribution[2, z], x]*d[y, x] + c[z], {x, 0, 1}]

NMaximize[{y - p, U[e[y], y, p] == 0, y >= 0, p >= 0}, {y, p}]


Do you see what i messed up?

PS: I try to maximize y-p given the constraint U[e[y], y, p] == 0

• You're trying to Maximize an equation? Or are you trying to Maximize y-p subject to constraints? Either way, you're lacking curly brackets. Commented Oct 20, 2016 at 10:30
• I try to maximze y-p. I included the brackets now Commented Oct 20, 2016 at 11:18
• One error I'm spotting in your code is that you're re-using variable in places where you shouldn't. For example, the variable e is used as both a function and as the optimization variable in NMinimize. Furthermore, NMinimize doesn't return just a number but also a Rule containing the position of the minimum, so you need to pull out the right answer before you can insert the result into other functions. Commented Oct 20, 2016 at 13:41
• you are actually re-utilizing the symbol e for three different things. While that may or may not be an actual problem it sure makes things hard to follow. Is e[y] intended to be the minimum value or the value of the local e at the minimum? Commented Oct 20, 2016 at 15:28

both of your integrals can be done analytically with appropriate assumptions, note the way I formulated things both integrals are in non-delayed defintions.

c[eloc_] = 1/2*eloc + 1;
d[y_, x_] = x*y^2;
f[e_ /; e > 0, y_] = Assuming[{0 < x < 1, e > 0},
Simplify[
Integrate[Simplify[PDF[BetaDistribution[2, e], x]*d[y, x] + c[e]],
{x, 0, 1}]]];
efun[y_?NumericQ] := e /. NMinimize[{f[e, y], e >= 0}, e][[2]]
(* this is the value of e that minimizes f *)
U[z_ /; z > 0, y_, p_] = p - Assuming[{0 < x < 1, z > 0},
Integrate[
PDF[BetaDistribution[2, z], x]*d[y, x] + c[z], {x, 0, 1}]]

ContourPlot[ U[efun[y], y, p] == 0, {y, 0, 2}, {p, 1, 3}]


I'd suggest you review this and make sure its right..

FindMaximum[{y - p, U[efun[y], y, p] == 0, y > 0,   p > 0}, {{y, 1}, {p, 1}}]


{-0.75, {y -> 0.5, p -> 1.25}}