0% found this document useful (0 votes)
9 views2 pages

Lagranage's Multiplier Method For Two Variables

lagrange's multiplier method for two variables
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Lagranage's Multiplier Method For Two Variables

lagrange's multiplier method for two variables
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Lagranage’s Multiplier Method for two variables

Aim: Solving and visualizing constrained maxima and minima

Find the extreme values of the function f ( x , y )=x 2+ 2 y 2 on the circle x 2+ y 2=1
Solution:

Find all the partial derivatives

Solve the system

MATLAB Syntax used:

jacobian(f,v) jacobian(f,v) computes the Jacobian matrix of f with respect to v.


Solve Symbolic solution of algebraic equations, The input to
solve can be either symbolic expressions or strings
ezcontour(f) ezcontour(f) plots the contour lines of the function z = f(x,y) using
the contour function. The function plots f over the default interval [-
2π 2π] for x and y.
ezplot(f) ezplot(f) plots the curve defined by the function y = f(x) over the
default interval [-2π 2π] for x.

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.

You might also like