Lagranage's Multiplier Method For Two Variables
Lagranage's Multiplier Method For Two Variables
Find the extreme values of the function f ( x , y )=x 2+ 2 y 2 on the circle x 2+ y 2=1
Solution:
Matlab Code
clc
clear all
format compact
syms x y lam real
f= input('Enter f(x,y) to be extremized : ');
g= input('Enter the constraint function g(x,y) : ');
F=f-lam*g;
Fd=jacobian(F,[x y lam]);
[ax,ay,alam]=solve(Fd,x,y,lam);
ax=double(ax); ay=double(ay);
T = subs(f,{x,y},{ax,ay}); T=double(T);
epxl=min(ax);
epxr=max(ax);
epyl=min(ax);
epyu=max(ax)
D=[epxl-0.5 epxr+0.5 epyl-0.5 epyu+0.5 ]
ezcontourf(f,D)
hold on
h = ezplot(g,D);
set(h,'Color',[1,0.7,0.9])
for i = 1:length(T);
fprintf('The critical point (x,y) is (%1.3f,%1.3f).',ax(i),ay(i))
fprintf('The value of the function is %1.3f\n',T(i))
plot(ax(i),ay(i),'k.','markersize',15)
end
TT=sort(T);
f_min=TT(1);
f_max=TT(end);
Example 1
Find the extreme values of the function f ( x , y )=x 2+ 2 y 2 on the circle x 2+ y 2=1
Enter f(x,y) to be extremized :
x^2+2*y^2
Enter the constraint function g(x,y) :
x^2+y^2-1
Output:
The critical point (x,y) is (-1.000,0.000).The value of the function is 1.000
The critical point (x,y) is (1.000,0.000).The value of the function is 1.000
The critical point (x,y) is (0.000,-1.000).The value of the function is 2.000
The critical point (x,y) is (0.000,1.000).The value of the function is 2.000
Interpretation: The contour curves of f touches the constraint g at the critical points
Practice Problems:
1. Find the extreme values of the function f ( x , y )=3 x+ 4 y on the circle x 2+ y 2=1.