#03 (06/23/2025)

Another example of error analysis in numerical integration

numint.jpg
The (left) rectangular rule is expressed as
Rn = h ( f0 + f1 + f2 + f3 + …+ fn−1).
It was shown that
I  ∼ Rn + A h.
(1)
By halving the step size, one gets

I  ∼ R2 n + A h

2
.
(2)
Subtracting Eq.(1) from twice Eq(2), one obtains
I  ∼ 2 R2 nRn,
(3)
which eliminates the error in the order of h. Note that if h is the step size for 2 n partitions, the step size for n partitions is 2 h.
Hence,

I
 ∼ 
2 R2 nRn
=
2 h ( f0 + f1 + f2 + f3 + f4 + …+ f2 n − 1) − (2 h) (f0 + f2 + f4 + f6 + …+ f2 n − 2)
=
2 h (f1 + f3 + f5 + f7 + …+ f2 n − 1).
(4)
This is called the mid-point rectangular rule and is just as accurate as the trapezoidal rule.

Example


f(x) = 8 x2

 

2 − x2
 
,    
1

0 
f(x) dx = π.
  1. Left rectangular rule (5 points)

    I  ∼ 0.2 ( f(0) + f(0.2) + f(0.4) +f(0.6) + f(0.8)) = 2.36867.
    Way too underestimated (see the figure).

    hw_02_sol_1.jpg
  2. Mid point rule (5 points)

    I  ∼ 0.2 ( f(0.1) + f(0.3) + f(0.5) + f(0.7)+f(0.9)) = 3.1279.
    Much improved over the left rectangular rule.

    hw_02_sol_2.jpg
  3. Trapezoidal rule

    I  ∼  0.2

    2
    ( f(0) + 2 ×(f(0.2) + f(0.4) + f(0.6) + f(0.8)) + f(1.0) ) = 3.16867.
    The accuracy is the same as the midpoint rectangular rule.

    hw_02_sol_3.jpg

Numerical differentiation

The forward difference approximation for numerical differentiation can be refined using a similar method.
Noting that the error in forward difference is O(h), define
h f(x+h)−f(x)

h
.
(5)
We can write this as

h  ∼ D + A h,
(6)
where Df′(x).
Writing ∆h and ∆2h together, we have
h
 ∼ 
D + A h,
(7)
2h
 ∼ 
D + 2 A h,
(8)
from which, it follows
D
 ∼ 
2 ∆h − ∆2h
=
−3 f(x) + 4 f(x+h)−f(x+2h)

2h
,
(9)
which has the same accuracy as the central difference scheme.
x f(x)
1 1
2 8
3 27
4 64
5 125
6 216

f′(2) ∼  −3f(2)+4f(3)−f(4)

2
= 10.0

Some basics on infinite series

Only in rare occasions can we sum up an infinite series in a closed form (Fourier series, for example) hence it is necessary to carry out numerical approximation for most of infinite series. Therefore, it is extremely important to be able to know in advance whether a given infinite series converges or diverges.
s=0;
for i=1:100 
 s=s+1.0/i;
end;

fprintf('sum=%f\n',s);
Online Octave (Matlab)


#include <stdio.h>
int main()
{
double s=0; int i;
for (i=1;i<100;i++) s=s + 1.0/i;
printf("sum=%f\n",s);
return 0;
}
Online C compiler


Example
100

i=1 
1

i
≈ 5.187,     1000

i=1 
1

i
≈ 7.485,     5000

i=1 
1

i
≈ 9.094     10000

i=1 
1

i
≈ 9.787,
From the above, one tends to think that ∑1/n converges to a value around 10. In fact, the series ∑1/n diverges as n → ∞ but its divergence speed is so slow that an illusion follows.

The Riemann zeta (ζ) function (p-series)

The most important infinite series that can be used as a reference series is the Riemann zeta (ζ) function defined as
ζ(p) ≡

n=1 
1

np
.
(10)

p = 1

3
    ζ(1/3) = 1 + 1

3

2
+ 1

3

3
+ 1

3

4
+ …
p = 1

2
    ζ(1/2) = 1 + 1

√2
+ 1

√3
+ 1

√4
+ …
p = 1
    ζ(1) = 1 + 1

2
+ 1

3
+ 1

4
+ …
p = 2
    ζ(2) = 1 + 1

22
+ 1

32
+ 1

42
+ …
p = 3
    ζ(3) = 1 + 1

23
+ 1

33
+ 1

43
+ ……
Theorem: (Important) The p-series converges when p > 1.
(Proof) pseries1.jpg
For p < 1, it can be seen from the figure above that
1 + 1

2p
+ 1

3p
+ 1

4p
+ …+ 1

np
>

n+1

1 
1

xp
dx
=
1

1 − p
( (1 + n)1−p − 1 )
∞    as     n → ∞.
(11)
For p = 1, the above needs to be modified as
1 + 1

2
+ 1

3
+ 1

4
+ …+ 1

n
>

n+1

1 
1

x
dx
=
ln (n + 1)
∞    as     n → ∞.
(12)
For p > 1, pseries2.jpg

1

2p
+ 1

3p
+ 1

4p
+ …+ 1

np
<

n

1 
1

xp
dx
=
1

p − 1

1 − 1

np−1

1

p − 1
    as     n → ∞.
(13)
It is seen that ∑1/n10 converges faster than ∑1/n3.

Asymptotic notation and Landau-Bachmann magnitude (Big Oh)

The convergence or divergence of an infinite series can be determined by comparing the given series with another series whose convergence/divergence is already known by some other means. The following two definitions can be used to associate the given series with another series.

Definition (Asymptotic notation)

We say that f(x) is asymptotic to g(x) as xx0, i.e.
f(x)  ∼ g(x)     as     xx0
(14)
when

lim
xx0 
f(x)

g(x)
= 1.
(15)

Definition (Bachmann-Landau order of magnitude, aka Big Oh)

We say that f(x) is the Landau order of g(x), i.e.
f(x) = O(g(x)),
(16)
when |f(x)/g(x)| is bounded as xx0.
The Big Oh is less restrictive than the asymptotic notation. Note the equal sign (=) used in the Big Oh.

Examples


  1. 3 x4 + x + 8

    x2 + 2
     ∼ 3 x2     as     x → ∞,

  2. 3 x4 + x + 8

    x2 + 2
     ∼ 4     as     x → 0,

  3. 3 x4 + x + 8

    x2 + 2
    = O(x2)     as     x → ∞,

  4. 3 x4 + x + 8

    x2 + 2
    = O(x3)     as     x → ∞.

Convergence of infinite series

THEOREM (Comparison Test)

Two series, ∑an and ∑bn, of positive terms converge or diverge simultaneously if an  ∼ bn as n → ∞.

THEOREM (Comparison Test 2)

If an = O (bn) and ∑bn converges, ∑an converges. The converse is NOT true, i.e. the convergence of bn is a sufficient condition for the convergence of an but not a necessary condition.

Counterexamples


1

n3
= O(1),     1

n3
= O
1

n

,    1

n3
= O
1

n2

    n → ∞.

THEOREM (Ratio Test)

Consider a series ∑an of positive terms where |an+1/an|  ∼ r as n → ∞. The series converges if r < 1, diverges if r > 1, no information is gained if r = 1.

Example

The series


n=1 
n

3n
converges as


an + 1

an

=




n + 1

3n+1

n

3n




=

n + 1

n
1

3

1

3
< 1     as    n→ ∞.

THEOREM (Alternating series) Leibniz's test (aka Dirichlet's test)

If an > 0 and an ↓ 0 (monotonically going to 0) as n → ∞,
S  = a1a2 + a3a4 + a5a6 − …,
(17)
converges.
Proof
As S2n+2 = S2n+ (a2n+1a2n+2), S2 < S4 < S6 < S8 …. On the other hand, as S2n+1S2n−1− (a2na2n+1), it follows S1 > S3 > S5 > S7 > …. Therefore the interval, [S2n−1, S2n], goes to 0 as n→ ∞.

Example

The infinite sum


n=1 
(−1)n + 1

n
= 1 − 1

2
+ 1

3
1

4
+ 1

5
− …,
converges as an = 1/n goes to 0 monotonically.
Note that


n=1 
1

n
= 1 + 1

2
+ 1

3
+ 1

4
+ 1

5
+ …
diverges as this is the p series with p = 1. The latter diverges slowly and the former converges slowly (to ln 21).

Exercise of infinite series




  1. n2 + 2 n −1

    n4 + 3

    3/2

     
    This series is convergent as an  ∼ 1/n3.


  2. 1

    (n + 3)3/2
    This series converges as an  ∼ 1/n1.5 (p > 1).


  3. n

    n2 + 3 ln n
    This series diverges as an  ∼ 1/n.



  4. 1 + 1

    n2

    This series diverges as an ≠ 0 as n → ∞ 2.



  5. cos n

    2 n −1

    2

     
    This series converges as
    an 1

    (2n − 1)2
     ∼  1

    4 n2
    .


  6. (−1)n ln 
    1 + 1

    n

    This series converges per Leibniz's test, i.e ∑(−1)n is bounded and
    ln 
    1 + 1

    n

    ↓ 0
    as n → ∞.


  7. 1

    x2 + n2
    This series converges as an = O(1/n2).


  8. (−1)n

    2n
    This series is convergent as |an+1/an| → 1/2 (ratio test).


  9. ln 
    n2 − 1

    n2 + 1

    This series converges as
    ln 
    n2 − 1

    n2 + 1

    =
    ln
    1 − 1

    n2

    − ln
    1 + 1

    n2

     ∼ 
    2

    n2
    .

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

.
(18)
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).
(19)
Take the total derivative of Equation (19) 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



,
(20)
where
J





x

u
x

v
y

u
y

v






(21)
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)
.
(22)
Differentiating Equation (19) 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)
.
(23)
Therefore, it follows
∂(x, y)

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

∂(x, y)

−1

 
.
(24)
This is what is equivalent to Equation (18) in two-variable functions.
For the polar coordinate system, Equation (24) 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.
    (25)
    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,
    (26)
    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 3

    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).
    (27)
    With f(x) = 0, the above equation can be solved for x as
    x = xo f(xo)

    f′(xo)
    ,
    (28)
    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

      .
      (29)
      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).
      (30)
      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.
      (31)
  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






    ,
    (32)
    or

    0 = f(xo) + J (xxo),
    (33)
    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)
    .
    (34)
    Equation (33) can be solved for x as

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

    2
    .
    (36)
    (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






    .
    (37)
    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






    .
    (38)
    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
ln (1 + x) = x x2

2
+ x3

3
x4

4
+ …
Substitute x = 1 to get

ln 2 = 1 − 1

2
+ 1

3
1

4
+ …
2 Theorem: If ∑an converges, an → 0 as n → ∞.
(Proof): Assume


i=1 
ai = S.
The partial sum of an is defined as
sn n

i=1 
ai,     an = snsn−1.
As n→ ∞, both sn and sn−1 go to S. Hence, an → 0.
The equivalent statement to the above is:
If an does not go to 0 as n → ∞, ∑an diverges.
3 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
b1
a2
b2



.



File translated from TEX by TTH, version 4.03.
On 24 Jun 2025, 22:01.