All problems
Lagrange Multiplier Product
Problem
Maximize f(x, y) = a*x*y subject to the linear constraint b*x + c*y = d, with b and c nonzero.
The Lagrange conditions give x = d / (2*b) and y = d / (2*c). Return [x, y, f_max] where f_max = a * x * y.
Hint
Set the gradients of f and the constraint proportional and use the constraint to pin down the multiplier.
Test cases
case 1
in: [1,1,1,10]
expected: [5,5,25]
case 2
in: [2,1,2,8]
expected: [4,2,16]
case 3
in: [-1,2,5,20]
expected: [5,2,-10]
case 4
in: [3,4,6,24]
expected: [3,2,18]
Starter codePython
def lagrange_product(a, b, c, d):
# Return [x, y, f_max]
# Your code here
pass4 test cases · run your code against them in the editor