MATH661 Homework 1 - Number approximation

Posted: 08/23/21

Due: 08/30/21, 11:55PM

  1. Construct a convergence plot in logarithmic coordinates for the Leibniz series approximation of π. Estimate the rate and order of convergence.

    Solution. The convergence of the Leibniz series partial sum sequence {Ln}n

    Ln=k=0n(-1)k2k+1,limnLn=π4,

    is shown in Fig. 1, and can be visually estimated to converge with order p=1. The rate of convergence is

    r=limnLn+1Ln=limn(1+(-1)n+1(2n+1)Ln)=1.

    Figure 1. Convergence of Leibniz series

    N=200; n=20:20:N;
    function Leibniz(n)
      k=0:n
      sum((-1).^k ./ (2*k.+1))
    end;
    err=log.(abs.(Leibniz.(n) .- π/4));
    clf(); plot(log.(n),err,"-o"); xlabel("log(n)"); ylabel("log(err)"); title("Leibniz series convergence"); grid("on"); plot([3,4],[-5,-7],"-"); plot([3,4],[-5,-6],"-");
    savefig(homedir()*"/courses/MATH661/images/H01Fig01.eps")
  2. Apply Aitken acceleration to the Leibniz partial sums sequence. Construct the convergence plot. Estimate the rate and order of convergence.

    Solution. The Aitken-accelerated sequence {An}n has general term

    An=Ln-(Ln-Ln-1)2Ln-2Ln-1+Ln-2,

    with convergence plot shown in Fig. 2, indicating faster than quadratic growth.

    Figure 2. Convergence of Aitken acceleration of Leibniz series

    N=40; n=1:N; L=Leibniz.(n); A=copy(L);
    for n=3:N
      ΔL = L[n] - L[n-1]
      Δ2L = L[n] - 2*L[n-1] + L[n-2]
      A[n] = L[n] - ΔL^2/Δ2L
    end
    errL=log.(abs.(L .- π/4)); errA=log.(abs.(A .- π/4));
    clf(); plot(log.(n),errL,"-o"); plot(log.(n),errA,"-x"); xlabel("log(n)"); ylabel("log(err)"); title("Aitken-accelerated Leibniz series convergence"); grid("on"); plot([2,4],[-6,-8],"-"); plot([2,4],[-6,-10],"-");
    savefig(homedir()*"/courses/MATH661/images/H01Fig02.eps")
  3. Construct a convergence plot for the Ramanujan series approximation of π. Estimate the rate and order of convergence.

    Solution. The general term

    rk=(4k)!(1103+26390k)(k!)43964k

    in the Ramanujuan series

    Rn=229801k=0n(4k)!(1103+26390k)(k!)43964k,limnRn=1π,

    decreases rapidly. Applying Stirling's formula, lnn!nln-n (valid for large n), gives

    lnrk(4k)ln4k-4k+ln(1103+26390k)-4(klnk-k)-4kln396,
    lnrk-4kln99+ln(1103+26390k)
    rˇk=99-4k(1103+26390k)

    Since r0=1103103, terms smaller than 103ϵ (ϵ is machine epsilon) would not appreaciably contribute to the sum

    ε=eps(Float64); kmax = log(10^3*ε)/(-4*log(99))

    1.5851544170976106

    ř(k)=99.0^(-4*k)*(1103+26390*k)

    ř

    ř.(0:4)

    [ 1103.0 0.00028620772638853663 5.839426693578139e-12 9.056224058132163e-20 1.2527103941143644e-27 ] (1)

    The above computation indicates that 2 terms of the sum should already give an approximation within machine precision. Floating point evaluation of rk should avoid intermediate computations close to overflow or undeflow. For example, the following evaluation is accurate in floating point arithmetic

    r(k) = (factorial(4*k)/(factorial(k))^4)*(1103.0+26390*k)/396.0^(4*k);
    r.(0:4)

    [ 1103.0 2.6831974348925308e-5 2.2453850201136646e-13 1.9950749944958964e-21 1.8393545314677564e-29 ] (2)

    In contrast, a different order of operations leads to incorrect results due to close-to-overflow conditions.

    rbad(k)=factorial(4*k)*(1103+26390*k)/(factorial(k))^4/396^(4*k);
    rbad.(0:4)

    [ 1103.0 2.6831974348925308e-5 -3.383976671091512e-11 3.2409901671873466e-9 8.916491639979272e-7 ] (3)

    Since there are only three partial sums that can be formed in floating point arithmetic, it is improper in this case to define an order of convergence based on the concept of a limit.

    R(n) = 2*sqrt(2.)/9801*sum(r.(0:n));
    R.(0:2)

    [ 0.31830987844047015 0.31830988618379064 0.3183098861837907 ] (4)

    (R.(0:2) .- 1/π)*π

    [ -2.4326358923863425e-8 -1.743934249004316e-16 0.0 ] (5)

    eps(Float64)

    2.220446049250313e-16

    From above computations, machine precision is achieved at n=1 (recall that machine epsilon is indistinguishable from zero, 1+ϵ=1).

  4. Construct a convergence plot for the continued fraction approximation of π. Estimate the rate and order of convergence.

    Solution. The continued fraction

    π+3=6+126+,Fn=b0+Kk=1nakbk,ak=(2k-1)2,bk=6,

    can be evaluated through multiple techniques:

    Iteration. The sequence of fractions is explicitly unrolled into a loop.

    function πIter(n)
      a(k) = (2*k-1)^2; b(k) = 6.0
      F = b(n)
      for k = n:-1:1
        F = b(k) + a(k)/F
      end
      return F
    end;
    πIter.(0:5)

    [ 6.0 6.166666666666667 6.133333333333334 6.145238095238096 6.13968253968254 6.142712842712843 ] (6)

    Recursion. The sequence of fractions is evaluated by a self-referential function. Note in the implementation the use of multi-method functions:

    • πRecur(k,n) is the recursive function with two arguments

    • πRecur(n) is a single-argument function that initializes the recursion

    function πRecur(k,n)
      a(k) = (2*k-1)^2; b(k) = 6.0
      if (k==n)
        return b(n)
      else
        return b(k+1) + a(k+1)/πRecur(k+1,n)
      end  
    end;
    πRecur(n) = πRecur(0,n);
    πRecur.(0:5)

    [ 6.0 6.166666666666667 6.133333333333334 6.145238095238096 6.13968253968254 6.142712842712843 ] (7)

    Composition. The continued fraction is evaluated through composition of functions

    Tn=t0t1tn=k=0ntk=Tn-1tn

    t0(z)=6+z,t1(z)=16+z,,tk(z)=(2k-1)26+z,..

    Fn=Tn(0)

    function t(k,z)
      a(k) = (2*k-1)^2; b(k) = 6.0
      if (k==0) 
        return b(0) + z
      else
        return a(k)/(b(k)+z)
      end
    end;
    function T(n,z)
      if (n==0)
        return t(0,z)
      else
        return T(n-1,t(n,z))
      end
    end;
    πComp(n) = T(n,0);
    n=5; [πIter(n) πRecur(n) πComp(n)]

    [ 6.142712842712843 6.142712842712843 6.142712842712843 ] (8)

    From convergence study in Fig. 3, the continued fraction order of approximation is p3. This is often encountered: continued fraction approximations that lead to higher than second-order convergence.

    Figure 3. Convergence of continued fraction approximation of π

    N=200; n=20:20:N;
    err=log.(abs.(πIter.(n) .- (π+3)));
    clf(); plot(log.(n),err,"-o"); xlabel("log(n)"); ylabel("log(err)"); title("Continued fraction convergence"); grid("on"); plot([3,4],[-12,-13],"-"); plot([3,4],[-12,-14],"-"); plot([3,4],[-12,-15],"-");
    savefig(homedir()*"/courses/MATH661/images/H01Fig03.eps")
  5. Completely state the mathematical problem of computing the absolute value

    |x|,x.

    Find the absolute and relative condition numbers.

    Solution. The mathematical problem is

    f:+,f(x)=|x|

    From the overview of mathematical problem conditioning [1], the absolute condition number introduced in [2] is given by

    κ^=|f'(x)|=1

    where f is differentiable. The relative condition number is also equal to one

    κ=|x||f'(x)||f(x)|=1.

    The only remaining point is behavior at x=0. By definition

    κ^=limε0sup|δx|ε|f(0+δx)-f(0)||δx|=limε0sup|δx|ε|δx||δx|=1.

    The relative condition number is

    κ^=limε0sup|δx|ε|f(0+δx)-f(0)||ε||δx||f(ε)|=1.

    Taking the absolute value is a well-conditioned mathematical problem.

  6. Completely state the mathematical problem of computing a difference.

    x1-x2,x1,x2.

    Find the absolute and relative condition numbers.

    Solution. The mathematical problem is

    f:×,f(x)=x1-x2,

    with absolute condition number

    κ^(𝒙)=limε0sup||δ𝒙||ε|δx1-δx2|||δ𝒙||.

    Choosing the 1-norm,

    κ^(𝒙)=limε0sup||δ𝒙||ε|δx1-δx2||δx1|+|δx2|limε0sup||δ𝒙||ε|δx1|+|δx2||δx1|+|δx2|=1.

    The relative condition number is

    κ^(𝒙)=limε0sup||δ𝒙||ε|δx1-δx2||δx1|+|δx2||x1|+|x2||x1-x2|.

    Note that the relative condition number becomes arbitrarily large close to the x1=x2 bisector. Interpret the above to signify:

Bibliography

[1]

Nick Higham. What Is a Condition Number? mar 2020.

[2]

John R. Rice. A Theory of Condition. SIAM Journal on Numerical Analysis, 3(2):287–310, jun 1966. Publisher: Society for Industrial and Applied Mathematics.