Project

a new title

Minimization of a objective function using Lagrange multipliersObjective function      5 – (x-2)^2 – 2(y-1)^2                       (we have to minimize the function) Subject to : Constraint    x + 4y = 3Solution:f(x,y) = 5 – (x-2)^2 – 2(y-1)^2g(x,y) = x + 4y = 3 = cUsing Lagrange multipliers,F(x,y,k) = f(x,y) – k[(g(x,y) – c]F(x,y,k) =  5 – (x-2)^2 – 2(y-1)^2  - k[x +4y – 3]Partial differentiation of F(x,y,k) wrt to x ,y and k and then equating to zero(∂F(x,y,k))/∂x=   (∂{5 – (x-2)^2– 2(y-1)^2  - k[x +4y – 3]})/∂x = 0                          -2x + 4 – k = 0                     x =    (4-k)/2    --------------------------- (1)(∂F(x,y,k))/∂y=   (∂{5 – (x-2)^2– 2(y-1)^2  - k[x +4y – 3]})/∂y = 0-4y + 4 – 4k = 0                                     y = 1 – k -------------------------------------(2)                       (∂F(x,y,k))/∂k=   (∂{5 – (x-2)^2– 2(y-1)^2  - k[x +4y – 3]})/∂k = 0-x – 4y + 3 = 0Substitute value of x and y in this equation and solve for k value    k = 2/3Putting value of k in equation 1 and 2 and hence solve for x and y valuex = 5/3                                y = 1/3 Putting value of x and y in objective function to get minimum value                                   Minimum value = 4

python code for above problem

inputs : variables,objective function,constraint equation

import sympy as sp#INPUTS   (variables,objective function , constraint function )x,y,k = sp.symbols('x y k')minimization_function = 5 - (x-2)**2 - 2*(y-1)**2constraint_function = x + 4*y -3     # constraint condition  x + 4y = 3#solve by lagrange multiplier minimization methodf = minimization_function - k*(constraint_function)#partial differentiation of f w.r.t variables and equate to zero and hence find values of variables by solving pf_x = sp.diff(f,x) print('Equation no. 1)  '+str(pf_x)+' = 0\n')pf_y =sp.diff(f,y) print('Equation no. 2)  '+str(pf_y)+' = 0\n')pf_k =sp.diff(f,k)print('Equation no. 3)  '+str(pf_k)+' = 0\n')value1 = sp.solve(pf_x,x)x_k = value1[0]print('\tx(in terms of k) = '+str(x_k))value2 = sp.solve(pf_y,y)y_k = value2[0]print('\n\ty(in terms of k) = '+str(y_k))# Substitution of values of x and y in third equationpf_k = pf_k.subs(x,x_k)pf_k = pf_k.subs(y,y_k)#Calculation of values of variablesvalue3 = sp.solve(pf_k,k)k_value = value3[0]print('\n\t k = '+str(k_value))x_value = x_k.subs(k,k_value)print('\n\t x = '+str(x_value))y_value = y_k.subs(k,k_value)print('\n\t y = '+str(y_value))val_of_minfunction = minimization_function.subs(x,x_value)val_of_minfunction = val_of_minfunction.subs(y,y_value)print('\n   value of objective function after minimization = '+str(val_of_minfunction))

output screen :

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.