All problems
Lagrange Multipliers 3-Variable
Problem
Maximize f(x, y, z) = x*y*z subject to x + y + z = s with s > 0 and x, y, z positive.
By symmetry the optimum is x = y = z = s/3, giving f_max = s^3 / 27. Return [x, y, z, f_max].
Hint
The Lagrange conditions x = y = z follow immediately from symmetry.
Test cases
case 1
in: [3]
expected: [1,1,1,1]
case 2
in: [6]
expected: [2,2,2,8]
case 3
in: [9]
expected: [3,3,3,27]
case 4
in: [1]
expected: [0.3333333333333333,0.3333333333333333,0.3333333333333333,0.037037037037037035]
Starter codePython
def lagrange_product_3(s):
# Return [x, y, z, f_max]
# Your code here
pass4 test cases · run your code against them in the editor