#08 (09/16/2024)

Application:Lagrange multiplier

As an application of the theory of implicit functions, the Lagrange multiplier method is discussed here. We want to extremize f(x, y) subject to the constraint, g(x, y) = 0. Assuming g(x, y) = 0 can be solved for y as y = y(x), this is substituted into the object function of f(x, y) as f(x, y(x)) thus we can look at f(x, y(x)) as a function of x. The candidates of x's to extremize f can be obtained by differentiating f with respect to x as
f′(x) = fx + fy y′ = 0,
(1)
where y′ in Eq.(1) can be obtained from g(x, y) = 0 as
y′ = − gx

gy
.
(2)
Substituting Eq.(2) to Eq.(1) yields

fx

gx
= fy

gy
≡ λ,
(3)
where λ is a newly introduced parameter called the Lagrange multiplier. The development above implies that when extremizing f(x, y) subject to g(x, y) = 0, instead of working on f(x, y), one can try extremizing

f*f(x, y) − λg(x, y),
(4)
without any constraint, i.e. partially differentiating Eq.(4) with respect to x, y and λ as
f*

x
=
fx − λgx = 0,
(5)
f*

y
=
fy − λgy = 0,
(6)
f*

∂λ
=
g = 0.
(7)
The above equations form a set of simultaneous equations for x, y and λ.

Example 1

Find the shortest distance from the origin (0, 0, 0) to the plane, a x + b y + c z = d.

f(x, y, z) = x2 + y2 + z2min
(8)

subject to g(x, y, z) = a x + b y + c zd = 0.
(9)
Instead of minimizing f(x, y, z) with the constraint, one can try minimizing f*(x, y, z) ≡ f(x, y, z) − λg(x, y, z) with respect to x, y, z and λ without any constraint.

f*

x
=
2 x− λa = 0,
(10)
f*

y
=
2 y− λb = 0,
(11)
f*

z
=
2 z− λc = 0,
(12)
f*

∂λ
=
a x + b y + c zd = 0.
(13)
Solving the above set of simultaneous equations yields

x
=
λa

2
(14)
y
=
λb

2
(15)
z
=
λc

2
(16)
λ
=
2 d

a2 + b2 + c2
,
(17)
or equivalently

x
=
ad

a2 + b2 + c2
(18)
y
=
bd

a2 + b2 + c2
(19)
z
=
cd

a2 + b2 + c2
,
(20)
so the minimum distance is


 

x2 + y2 + z2
 
= d




a2 + b2 + c2
.
(21)
Alternative approach: Read the problem as Find the shortest distance from the origin (0, 0, 0) to the plane, a x + b y + c z = d.
lagrange_multi.jpg
The plane, a x + b y + c z = d, is also expressed as

a·x = d,
(22)
where a = (a, b, c) and x = (x, y, z). Equation (22) implies that the vector a is perpendicular to the plane (as was shown in class). Hence, the vector from the origin that minimizes the distance to the plane must be expressed as

x = t a,
(23)
where t is a parameter. By substituting Eq.(23) into Eq.(22), one obtains

a ·ta = t a·a = d.
(24)
Hence, t can be solved as
t = d

a·a
.
(25)
From Eq.(23), it follows
x = d

a·a
a,
(26)
and the length of x is

| x |
=
| d

a·a
a |
=
d

|a|2
|a|
=
d

|a|
=
d



 

a2 + b2 + c2
 
.
(27)

Example 2

Find the shortest distance from (1, 0) to x3 − 2 y2 = 0.
lagrange_1.jpg
(Solution) Let
f* ≡ (x −1)2 + y2 − λ(x3 − 2 y2),
it follows

f*

x
=
2 (x − 1) − 3 x2 λ = 0,
(28)
f*

y
=
2 y + 4 y λ = 0,
(29)
f*

∂λ
=
x3 + 2 y2 = 0.
(30)
The above equations can be solved as (real roots)

(x, y, λ) = ( 2

3
, 2

3 √3
, − 1

2
)    or     ( 2

3
, − 2

3 √3
, − 1

2
),
(31)
both of which yield

d =

 

(x−1)2 + y2
 
=   ⎛


7

27
 
 ∼ 0.509175.
(32)
Sample MATLAB/Octave code:
x=1; y=1; lambda=1;

for i=0:10
 eqs=[ 2*(x-1)-3*x*x*lambda ; 2*y+4 *y *lambda ; -x^3+2*y*y];

 jacob=[2-6*x*lambda, 0, -3*x*x; 0, 2+4*lambda, 4*y; -3*x*x, 4*y, 0];

 right=inv(jacob)*eqs;

 x=x-right(1);
 y=y-right(2);
 lambda=lambda-right(3);
end;

fprintf('%f %f %f\n', x, y,lambda);
fprintf('%f', sqrt((x-1)^2+y^2));

Online C compiler
Online MATLAB/Octave
Wolfram Alpha

Leibniz integral rule

The Leibniz integral rule is known as the Lagrangian derivative or the material derivative in fluid mechanics.
Problem: Given
I(t) ≡
b(t)

a(t) 
f(x, t) d x,
(33)
Find I′(t).

Approaches

Method 1: (not discussed in class)
Let
F(x, t) ≡
x

0 
f(y, t) d y.
(34)
Note that the integral variable has been changed to y from x to avoid confusion with the upper bound so that

F(x, t)

x
= f(x, t).
(35)
Using F(x, t), I(t) can be written as

I(t) = F(x, t)|x = b(t)F(x,t)|x = a(t),
(36)
hence

I′(t)
=

F

x
|x = b(t) db(t)

dt
+F

t
|x = b(t)

F

x
|x = a(t) da(t)

dt
+F

t
|x = a(t)
=
f(x,t)|x = b(t) db(t)

dt
f(x,t)|x = a(t) da(t)

dt
+F

t
|x = b(t)|−F

t
|x = a(t)|
=
f(x,t)|x = b(t) db(t)

dt
f(x,t)|x = a(t) da(t)

dt
+
b(t)

0 
f

t
dy
a(t)

0 
f

t
dy
=
f(x,t)|x = b(t) db(t)

dt
f(x,t)|x = a(t) da(t)

dt
+
b(t)

a(t) 
f

t
dy
=
f(b(t), t) db(t)

dt
f(a(t), t) da(t)

dt
+
b(t)

a(t) 
f

t
dy.
(37)
Method 2:(discussed in class)

I(t + ∆t) − I(t)

t
=

b + ∆b

a + ∆a 
f(x, t + ∆t) dx
b

a 
f(x, t) dx

t
=

b

a 
f(x, t + ∆t) dx +
b + ∆b

b 
f(x, t + ∆t) dx
a + ∆a

a 
f(x, t + ∆t) d x
b

a 
f(x, t) dx

t
 ∼ 

b

a 
f(x, t + ∆t) − f(x, t)

t
dx +b

t
f(b, t)−a

t
f(a, t).
(38)
By letting ∆t → 0,
I′(t) =
b

a 
f

t
dx + b′(t) f(b, t) − a′(t) f(a, t).
(39)
Example 1
I(t) ≡
t2

t 
sin (x2 t) dx.
Example 2 Evaluate
I
1

0 
x − 1

ln x
d x.
by starting with this integral:
I(t) ≡
1

0 
xt−1

ln x
dx.
Example 3 Evaluate

1

0 
xt ln x d x
by starting with the known integral

I(t) ≡
1

0 
xt d x.

Interpretation

The Leibniz integral rule is also known as the material derivative or the Lagrangian derivative in fluid mechanics. The function, f(x, t), can be interpreted as a physical quantity such as the mass density and momentum that flows with a moving particle. The function, I(t), is the collection of such a quantity over a region where the material is defined. Therefore, a′(t) and b′(t) are the velocities of the boundary of the material. With this interpretation, Eq.(39) can be written as

I′(t)
=

b

a 
f

t
dx +[ v f(x, t)]a(t)b(t)
=

b

a 
f

t
dx +
b

a 
d

dx
( v(x, t) f(x, t)) dx
=

b

a 

f

t
+ d

dx
( v(x, t) f(x, t))
dx.
(40)
The result of Eq.(40) can be extended to two-dimensional space as
I′(t) =



 

f

t
+∇·(v f)
dS,
(41)
where
I(t) ≡



 
f(x, t) dS.
If we interpret f(x, t) as the mass density, ρ(x,t), M(t) ≡ ∫∫ρ(x, t) d s is the total mass of the material and its material derivative must be 0 as the mass has to be conserved in Newtonian mechanics. Thus,
M′(t)
=




 

∂ρ

t
+∇·(v ρ)
dS
=
0
(42)
which is equivalent to
∂ρ

t
+∇·(v ρ) = 0,
(43)
which is known as the equation of continuity.




File translated from TEX by TTH, version 4.03.
On 16 Sep 2024, 14:33.