0
$\begingroup$

If a + b + c + d == 63 then find the Maximum of a b + b c + c d. I tried using If, With
but unable to get the solution/answer. Any help is appreciated. The answer is 991.

$\endgroup$
4
  • 1
    $\begingroup$ {a,b,c,d}>=0? $\endgroup$
    – cvgmt
    Aug 6 at 14:32
  • $\begingroup$ Maximize[{a b + b c + c d, a + b + c + d == 63}, {a, b, c, d}] should work but does not, for some reason. $\endgroup$
    – Roman
    Aug 6 at 14:51
  • 1
    $\begingroup$ Aside from the problem being unbounded as @cvgmt pointed out, one can see from the Hessian that any critical point is a saddle point: D[z /. First@ Solve[{z == a b + b c + c d, a + b + c + d == 63}, {z, d}], {{a, b, c}, 2}] // Eigenvalues // N. On a bounded domain, the extrema will be on the boundary. $\endgroup$
    – Michael E2
    Aug 6 at 17:45
  • 2
    $\begingroup$ Need to add a condition {a, b, c, d} ∈ PositiveIntegers or {a, b, c, d} ∈ Integers,{a,b,c,d}>0. $\endgroup$
    – cvgmt
    Aug 7 at 14:46
5
$\begingroup$

Updated

Maximize[{a*b + b*c + c*d, 
  a + b + c + d == 63, {a, b, c, d} ∈ PositiveIntegers}, {a, 
  b, c, d}]

{991, {a -> 1, b -> 30, c -> 31, d -> 1}}

Original

We must add some conditions since without it the question is unbounded. See the example as below.

a b + b c + c d /. 
  FindInstance[{a + b + c + d == 63}, {a, b, c, d}, Reals, 20] // N

{5502.96, 6579.89, -10891.8, 2442.18, -6627.59, -7054.56, 2829.6, 415.69, 305.09, 918.08, 410.02, -6148.25, -6412.11, -10460.1, 1677.84, -4958.71, 1965.59, -2993.25, 315.68, -1949.59}

Maximize[{a b + b c + c d, 
  a + b + c + d == 63, {a, b, c, d} >= 0}, {a, b, c, d}]

{3969/4, {a -> 0, b -> 16, c -> 63/2, d -> 31/2}}

$\endgroup$
1
  • $\begingroup$ Thank you very much. $\endgroup$
    – Littlewood
    Aug 9 at 2:07
4
$\begingroup$

QuadraticOptimization can optimize quadratic functions with linear constraints:

QuadraticOptimization[-(a b + b c + c d), a + b + c + d == 63, {a, b, c, d}]
(* {a -> 0., b -> 31.5, c -> 31.5, d -> 0.} *)

Alternatively use Solve on the KKT-conditions:

{D[a b + b c + c d + μ (a + b + c + d - 63), {{a, b, c, d}, 1}],
   a + b + c + d - 63} == 0 // Solve
(* {{a -> 0, b -> 63/2, c -> 63/2, d -> 0, μ -> -(63/2)}} *)
$\endgroup$
3
$\begingroup$

You can solve it using the Lagrange multipliers technique as follows:

obj = a b + b c + c d;
L = obj + lambda (a + b + c + d - 63)
vars = Variables[L]
grad = Grad[L, vars]
sols = Solve[grad == 0, vars]
results = {obj, vars} /. sols[[1]]

(*{3969/4, {0, 63/2, 63/2, 0, -(63/2)}}*)
$\endgroup$

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.