# Symbolic quadratic constrained maximization with non-negativity constraints?

Dear Mathematica users,

I attempted to maximize the below quadratic function K, subject to x1+x2<=A, and a series of non-negativity conditions. Unfortunately, running the below syntax provides no solution as the kernel keeps running for hours without a result.

How can a symbolic solution for x1 and x2 be obtained?

Thank you for your help and I hope my question is clear.

ClearAll["Global*"]
{xx = {x1, x2}, GG = {g1, g2}, BB = {1, 1}, QQ = {{q1, q12}, {q12, q2}}}
Alpha = (r/(A v))
K = GG.xx - (Alpha/2)  xx.QQ.xx
region = {BB.xx <= A, x1 >= 0 , x2 >= 0 , A >= 0, r >= 0, v >= 0, q1 >= 0, q2 >= 0}
Maximize[{K, region}, {x1, x2}]

• Hi ! Why don't you try and maximize a simple function first, see if you are actually doing the right thing and then dive into the deep waters ? As a first step you are trying to re-define a built-in function (K), so you should change the name of your variable. Commented Dec 31, 2014 at 15:37
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! Commented Dec 31, 2014 at 17:15

The following does return a result:

pp1= Reduce[{D[K, x1] == 0     && D[K, x2] == 0 &&
D[K, {x1, 2}] < 0 && D[K, {x2, 2}] < 0 &&
D[K, {x2, 2}] D[K, {x1, 2}] > D[K, x1, x2]^2 &&
And @@ region}, {x1, x2}, Reals]


Solve[] also works:

pp2 = Solve[{D[K, x1] == 0     && D[K, x2] == 0 &&
D[K, {x1, 2}] < 0 && D[K, {x2, 2}] < 0 &&
D[K, {x2, 2}] D[K, {x1, 2}] > D[K, x1, x2]^2 &&
And @@ region}, {x1, x2}, Reals]


If the conditions for the existence of a maximum are met (they are convoluted and I haven't analyzed them), the coordinates are:

{x1, x2} /. pp2 /. ConditionalExpression[a_, b_] :> a // FullSimplify
(*
{{(A (g2 q12 - g1 q2) v) /((q12^2 - q1 q2) r),
(A (-g2 q1 + g1 q12) v)/((q12^2 - q1 q2) r)}}
*)


and the value of the maximum is

K /. pp2 /. ConditionalExpression[a_, b_] :> a // FullSimplify
(*
{-((A (g2^2 q1 - 2 g1 g2 q12 + g1^2 q2) v)/(2 (q12^2 - q1 q2) r))}
*)


Example:

vals = {q1 -> 10, q2 -> 1, q12 -> -2, A -> 1, g1 -> 10, g2 -> -1, r -> 100, v -> 1};
Show[Plot3D[K /. vals, {x1, 0, .018}, {x2, 0, .018}],
Graphics3D[{PointSize[.05], Red, Point[{x1, x2, K} /. pp2 /. vals]}]]


{x1, x2, K} /. pp2 /. vals
(*
{{1/75, 1/60, 7/120}}
*)
`