#06 (09/11/2023)

Jacobian

Question: Consider the polar coordinate system, (r, θ), defined by
x = r cos θ,     y = r sin θ.
It follows
d x

d r
= cos θ.
On the other hand, the above relationship can be inverted as
r =

 

x2 + y2
 
,     θ = arctan  y

x
.
Thus,
d r

d x
= x




x2 + y2
= r cos θ

r
= cos θ.
Therefore, it was found that
d x

d r
= d r

d x
,
which looks odd, as you expect that
d x

d r
= 1


d r

d x

.
So what gives ?
Answer: If the transformation is for one variable functions, i.e., x = x(u), it always follows
d x

d u
= 1


d u

d x

.
(1)
However, this relationship does not hold for transformations for multi-variable functions. Consider the transformation from (x, y) to (u, v) defined as
x = x(u, v),     y = y(u, v).
(2)
Take the total derivative of Equation (2) to obtain
d x
=
x

u
d u + x

v
d v,
d y
=
y

u
d u + y

v
d v,
or



d x
d y



=






x

u
x

v
y

u
y

v









d u
d v



=
J    


d u
d v



,
(3)
where
J





x

u
x

v
y

u
y

v






(4)
is called the Jacobian matrix. As was noted in class, the Jacobian matrix is the generalization of partial derivatives in multi-variable functions.
The Jacobian matrix is also denoted as
∂(x, y)

∂(u, v)
.
(5)
Differentiating Equation (2) with respect to x and y, one gets
1 = x

u
u

x
+x

v
v

x
,
0 = x

u
u

y
+x

v
v

y
,
0 = y

u
u

x
+y

v
v

x
,
1 = y

u
u

y
+y

v
v

y
,
or



1
0
0
1



=



xu
xv
yu
yv






ux
uy
vx
vy



=
∂(x, y)

∂(u, v)
    ∂(u, v)

∂(x, y)
.
(6)
Therefore, it follows
∂(x, y)

∂(u, v)
=
∂(u, v)

∂(x, y)

−1

 
.
(7)
This is what is equivalent to Equation (1) in two-variable functions.
For the polar coordinate system, Equation (7) is expressed as



cos θ
r sin θ
sin θ
r cos θ



=



cos θ
sin θ
sin θ

r
cos θ

r




−1





 
.

Examples of Jacobian matrices

  1. Multiple integrals
    In single integrations, integration by substitution (u-substitution) is stated as

    b

    a 
    f(x) d x =
    β

    α 
    f(x(u)) d x

    d u
    d u.
    (8)
    In multiple integrations, the above formula can be extended to





    D 
    f(x, y) d x d y =



    D 
    f(x(u), y(v))
    ∂(x, y)

    ∂(u, v)

    d u dv,
    (9)
    where the determinant of the Jacobian matrix,
    | J | ≡
    ∂(x, y)

    ∂(u, v)

    ,
    is called the Jacobian determinant or simply the Jacobian. The Jacobian is hence interpreted as the scaling factor of an area element from one coordinate system to another.
    (Proof) Consider the area spanned by the two base vectors, AB and AC, below:
    jacob.jpg
    When the coordinates of point A are denoted as (x, y), the coordinates of the points B and C are expressed as (x + ∂x/∂u du, y + ∂y/∂u du) and (x + ∂x/∂v dv, y + ∂y/∂v dv), respectively, so the components of the vectors, AB and AC, are


    AB
     
    =

    x

    u
    du, y

    u
    du
    ,

    AC
     
    =

    x

    v
    dv, y

    v
    dv
    .
    Therefore, the area of the parallelogram spanned by the two vectors is 1

    dS
    =












    x

    u
    ,
    x

    v
    y

    u
    ,
    y

    v












    du dv
    =

    ∂(x, y)

    ∂(u, v)

    du d v
    =
    | J | d u dv.
    Exercise: Find |J| for the polar coordinate system:
    x = r cos θ,     y = r sin θ.
    (Answer)

    | J |
    =












    x

    r
    ,
    x

    ∂θ
    y

    r
    ,
    y

    ∂θ












    =






    cos θ,
    r sin θ
    sin θ,
    r cos θ






    =
    r cos2 θ+ r sin2 θ
    =
    r.
    Exercise: Evaluate
    I


    −∞ 
    ex2 dx.
    (Answer)
    I2
    =



    −∞ 
    ex2 dx


    −∞ 
    ey2 dy
    =



    −∞ 



    −∞ 
    e−(x2 + y2) dx dy
    =



    0 



    0 
    er2 r dr dθ
    =



    0 
    er2 r dr
    =
    2π× 1

    2
    =
    π,
    so
    I =

     

    π
     
    ,
    where r2 = t was used in evaluating ∫0r2 r er2 dr .
  2. Newton-Raphson method (single variable)
    The formula for the Newton-Raphson method can be derived by retaining the first two terms of the Taylor series of f(x) as
    f(x) = f(xo) + f′(xo) (xxo) + (higher order terms).
    (10)
    With f(x) = 0, the above equation can be solved for x as
    x = xo f(xo)

    f′(xo)
    ,
    (11)
    which can be used as the iteration scheme:
    For example, √2 can be computed by solving f(x) ≡ x2 − 2 = 0.
    f(x) = x2 −2,     f′(x) = 2 x.
    Start with x1 = 2.0 (initial guess), then,
    x1
    =
    2,
    x2
    =
    2− f(2)

    f ′(2)
    = 2 − 2

    4
    = 1.5,
    x3
    =
    1.5 − f(1.5)

    f ′(1.5)
    = 1.5 − 0.25

    3
    = 1.41667,
    x4
    =
    1.4167− f(1.4167)

    f ′(1.4167)
    = … = 1.4142.
    The convergence is attained after only 4 iterations.
    More examples:
    1. Square root of a ( = √a)
      Let f(x) = x2a. It follows
      xn+1
      =
      xn xn2a

      2 xn
      =
      1

      2

      xn + a

      xn

      .
      (12)
      Example (√3 = 1.732 …)
      x1 = 1,     x2 = 1

      2
      (1 + 3

      1
      ) = 2,    x3 = 1

      2
      (2 + 3

      2
      ) = 1.75,    x4 = 1

      2
      (1.75 + 3

      1.75
      ) = 1.732.
    2. Inverse of a ( = 1/a)
      Let f(x) = 1/xa. It follows
      xn+1
      =
      xn
      1

      xn
      a

      −1

      xn2
      =
      xn (2 − a xn).
      (13)
      Example (1/6 = 0.16667…)
      x1
      =
      0.2,     x2 = 0.2 (2 − 6×0.2)=0.16,    x3 = 0.16 (2 − 6×0.16) = 0.1664,
      x4
      =
      0.1664 (2 − 6×0.1664) = 0.166666.
    3. 1/√a
      Let f(x) = 1/x2a, it follows

      xn+1
      =
      xn 1/xn2a

      − 2/xn3
      =
      xn (3 − a xn2)/2.
      (14)
  3. Newton-Raphson method (multiple variables)
    We want to solve a set of (non-linear) simultaneous equations in the form of
    f1(x1, x2, x3, …xn)
    =
    0,
    f2(x1, x2, x3, …xn)
    =
    0,
    fn(x1, x2, x3, …xn)
    =
    0.
    By expanding each of the above by the Taylor series, one obtains
    f1(x)  ∼ f1 (xo) + f1

    x1


    x0 
    (x1x10) + f1

    x2


    x0 
    (x2x20) + …+ f1

    xn


    x0 
    (xnxn0),
    f2(x)  ∼ f2 (xo) + f2

    x1


    x0 
    (x1x10) + f2

    x2


    x0 
    (x2x20) + …+ f2

    xn


    x0 
    (xnxn0),
    fn(x)  ∼ fn (xo) + fn

    x1


    x0 
    (x1x10) + fn

    x2


    x0 
    (x2x20) + …+ fn

    xn


    x0 
    (xnxn0).
    If x satisfies
    f1(x) = 0,     f2(x) = 0,     …fn(x) = 0,
    the above equations can be written as






    0
    0
    :
    0






    =





    f1
    f2
    :
    fn






    +









    f1

    x1
    ,
    f1

    x2
    ,
    f1

    xn
    f2

    x1
    ,
    f2

    x2
    ,
    f2

    xn
    fn

    x1
    ,
    fn

    x2
    ,
    fn

    xn
















    x1x10
    x2x20
    :
    xnxn0






    ,
    (15)
    or

    0 = f(xo) + J (xxo),
    (16)
    where J is the Jacobian matrix defined as

    J










    f1

    x1
    f1

    x2
    f1

    xn
    f2

    x1
    f2

    x2
    f2

    xn
    fn

    x1
    fn

    x2
    fn

    xn










    =
    ∂(f1, f2, …, fn)

    ∂(x1, x2, …, xn)
    .
    (17)
    Equation (16) can be solved for x as

    x = xoJ−1 f(xo),
    (18)
    where J−1 is the inverse matrix of J.
    Example:
    Solve numerically for
    x3 + y2 = 1,     x y = 1

    2
    .
    (19)
    (Solution) Let
    f1x3 + y2 − 1,     f2x y 1

    2
    .
    It follows
    J = ∂(f1, f2)

    ∂(x, y)
    =


    3 x2,
    2 y
    y,
    x



    ,
    and
    J−1 =





    x

    3 x3 − 2 y2
    ,
    2 y

    3 x3 − 2 y2
    y

    3 x3 − 2 y2
    ,
    3x2

    3 x3 − 2 y2






    ,
    so
    J−1 f =





    x

    3 x3 − 2 y2
    ,
    2 y

    3 x3 − 2 y2
    y

    3 x3 − 2 y2
    ,
    3x2

    3 x3 − 2 y2









    x3 + y2 − 1
    x y − 1/2



    =





    x4x (y2+1)+y

    3 x3−2 y2
    4 x3 y−3 x2−2 y3+2 y

    6 x3−4 y2






    .
    (20)
    Hence the iteration scheme is



    xn+1
    yn+1



    =


    xn
    yn









    xn4xn (yn2+1)+yn

    3 xn3−2 yn2
    4 xn3 yn−3 xn2−2 yn3+2 yn

    6 xn3−4 yn2






    .
    (21)
    Sample C code:
    #include <stdio.h>
    #include <math.h>
    int main()
    {
    double x=1.0, y=1.0;
    int i;
    
    for (i=0;i<=10;i++)
      { x = x -(pow(x,4) + y - x*(1 + y*y))/(3*pow(x,3) - 2*y*y);
        y = y -(-3*x*x + 2*y + 4*pow(x,3)*y - 2*pow(y,3))/(6*pow(x,3) - 4*y*y);
      }
    
    printf("%f %f\n", x, y);
    return 0;
    }
    
    
    Sample Matlab/Octave code:
    x=1; y=1;
    for i=0:10
     eqs=[ x*x*x+y*y-1; x*y - 1/2];
     jacob=[3*x*x 2*y; y x];
     right=inv(jacob)*eqs;
     x=x-right(1);
     y=y-right(2);
    end;
    
    fprintf('%f %f\n', x, y);
    
    
    Sample Mathematica code:
    FindRoot[{x^3 + y^2 == 1, x y == 1/2}, {{x, 1}, {y, 1}}]
    
    
    Online C compiler
    Online Matlab/Octave
    Wolfram Alpha
    Starting (x, y) = (1.0, 1.0), the convergence was reached at (x, y) = (0.877275, 0.569947) after only 4 iterations. Note that this is just one of multiple roots. It is necessary to try different initial guess to obtain other roots.


Footnotes:

1 The area of a parallelogram spanned by vectors, a and b, is
S
=
a b sin θ
=


 

a2 b2 (1 − cos2  θ)
 
=


 

(a,a) (b,b) − (a,b)2
 
=


 

(a12 + a22)(b12 + b22) − (a1 b1 + a2 b2)2
 
=


 

(a1 b2a2 b1)2
 
=



a1
a2
b1
b2



.



File translated from TEX by TTH, version 4.03.
On 09 Sep 2023, 21:51.