Number Approximation - Exercises

1.Numbers

Exercise 1. Define one-to-one correspondences between the following sets of numbers:

  1. ๐”ผ={n|nโˆˆโ„•,nmod2=0.}, ๐•†={n|nโˆˆโ„•,nmod2=1.}

    Solution. f:๐”ผโ†’๐•†, f(n)=n+1 is one-to-one.

  2. โ„•, โ„ค

    Solution. f:โ„•โ†’โ„ค, with f defined by {0โ†’0,1โ†’-1,2โ†’1,3โ†’-2,4โ†’2,โ€ฆ} is one possibility. Introducing [x] as the integer part of xโˆˆโ„š, i.e. [x]=n with nโฉฝx<n+1, f can be expressed as

    f(n)=(-1)nmod2([n/2]+nmod2)

    In Julia xรทy is integer division, so for nโˆˆโ„• [n/2]=nรท2, and % is the modulo operator

    [4÷5 4÷4 4÷3 4÷2; 4%5 4%4 4%3 4%2]

    [ 0 1 1 2 4 0 1 0 ] (1)

    function f(n)
      q = n÷2; r = n%2; s = 1-2*r;
      s*(q+r)
    end

    f

    N=10; [collect(0:N)'; f.(0:N)']

    [ 0 1 2 3 4 5 6 7 8 9 10 0 -1 1 -2 2 -3 3 -4 4 -5 5 ] (2)

  3. โ„ค, โ„š

    Solution. Construct a table and introduce diagonal traversal to obtain the positive rationals p/q.

    Figure 1.

From above deduce |โ„•|=|๐”ผ|=|๐•†|=|โ„ค|=|โ„š|=โ„ต0.

Exercise 2. Provide an example to show |โ„|>|โ„•|.

Exercise 3. Let โ„•q={n|n.โˆˆโ„•,n<2q}. Answer the following questions analytically. Also provide a Julia implementation.

  1. Define a one-to-one correspondence f:โ„•2qโ†’โ„•qร—โ„•q

  2. Let f(m1)=(n1,p1), f(m2)=(n2,p2). Assume m1+m2โˆˆโ„•2q. Express f(m1+m2) in terms of n1,n2,p1,p2 .

  3. Assume m1โ‹…m2โˆˆโ„•2q. Express f(m1โ‹…m2) in terms of n1,n2,p1,p2 .

Exercise 4. Construct a one-to-one representation of the positions of atoms within an hexagonal lattice, f:โ„ค2โ†’โ„2. Implement f and f-1 as Julia functions. Use f to construct a graphical representation of a two-dimensional hexagonal lattice.

Exercise 5. Construct a one-to-one representation of the positions of atoms within an hexagonal lattice, f:โ„ค3โ†’โ„3. Implement f and f-1 as Julia functions. Use f to construct a graphical representation of a three-dimensional hexagonal lattice.

2.Approximation

Exercise 6. Write Julia code to compute machine epsilon ฯต for Float32 and Float64.

Exercise 7. Carry out a numerical experiment to verify the Axiom of floating point arithmetic within Float32, by computing ฯ€+r in Float32 and comparing to the result in Float64. Construct a scatter plot of (r,ฮต) with ฮต the error in computing ฯ€+r in Float32.

Exercise 8. Consider the approximations of e

Sn=1+12!+โ‹ฏ+1n!,Tn=1n!+1(n-1)!+โ‹ฏ+1.

  1. Write Julia functions to compute Sn, Tn.

  2. Determine if Sn=Tn for all nโˆˆโ„•.

  3. Determine if |Sn-Tn|<ฯต (ฯต is machine epsilon). Is the floating point axiom verified?

  4. Determine if |Sn-Tn|<(n-1)ฯต. Is the floating point axiom verified?

Exercise 9. Consider the approximations of ฯ€/2 given by Wallis's product

Sn=(21)โ‹…(23โ‹…43)โ‹…(45โ‹…65โ‹…67โ‹…87)โ€ฆpn,

Tn=pnโ‹…โ€ฆโ‹…(45โ‹…65โ‹…67โ‹…87)โ‹…(23โ‹…43)โ‹…(21)

  1. Find the general term pn.

  2. Determine if Sn=Tn for all nโˆˆโ„•.

  3. Determine if |Sn-Tn|<ฯต (ฯต is machine epsilon). Is the floating point axiom verified?

  4. Determine if |Sn-Tn|<(n-1)ฯต. Is the floating point axiom verified?

Exercise 10. Consider the approximations of e/2 given by Pippenger's product

Sn=(21)1/2โ‹…(23โ‹…43)1/4โ‹…(45โ‹…65โ‹…67โ‹…87)1/8โ€ฆpn,

Tn=pnโ‹…โ€ฆโ‹…(45โ‹…65โ‹…67โ‹…87)1/8โ‹…(23โ‹…43)1/4โ‹…(21)1/2

  1. Find the general term pn.

  2. Determine if Sn=Tn for all nโˆˆโ„•.

  3. Determine if |Sn-Tn|<ฯต (ฯต is machine epsilon). Is the floating point axiom verified?

  4. Determine if |Sn-Tn|<(n-1)ฯต. Is the floating point axiom verified?

3.Successive approximations

Exercise 11. Assume errors in successive numerical approximation of aโˆˆโ„, finite, are given by en=an-an-1,with{an}nโˆˆโ„•, an=n1/3.

  1. Construct a scatter plot of (n,en). Does the plot indicate convergence of the numerical approximation?

  2. Compute limnโ†’โˆžen.

  3. Suppose |en|<ฮต. What is an upper bound for |an-a|?

Exercise 12. Assume errors in successive numerical approximation of aโˆˆโ„, finite, are given by en=an-an-1,with{an}nโˆˆโ„•, an=n-1/2.

  1. Construct a scatter plot of (n,en). Does the plot indicate convergence of the numerical approximation?

  2. Compute limnโ†’โˆžen.

  3. Suppose |en|<ฮต. What is an upper bound for |an-a|?

Exercise 13. Consider a sequence of successive approximations of the derivative f'(x0)

dn=f(x0+1/n)-f(x0)1/n,nโˆˆโ„•.

  1. Is {dn}nโˆˆโ„• a convergent sequence?

  2. Is {dn}nโˆˆโ„• a Cauchy sequence?

  3. Construct a scatter plot of (n,dn) for f(x)=sinx, x0=ฯ€/4. Does the plot indicate convergence of {dn}nโˆˆโ„•?

  4. Construct a scatter plot of (n,en), en=dn-dn-1, for f(x)=sinx, x0=ฯ€/4. Does the plot indicate convergence of {dn}nโˆˆโ„•?

Exercise 14. Consider errors in successive approximations {an}nโˆˆโ„• given by en=an-an-1=en-1+en-2, i.e., errors at each step accumulate errors in previous two steps, with e1=e0=1. Is this a convergent approximation? Present both an analytical solution, and a numerical experiment.

Exercise 15. Consider errors in successive approximations {an}nโˆˆโ„• given by en=an-an-1=56en-1+16en-2, i.e., errors at each step are a weighted average of those in previous two steps, with e1=e0=1. Is this a convergent approximation? Present both an analytical solution, and a numerical experiment.

Exercise 16. Consider errors in successive approximations {an}nโˆˆโ„• given by en=an-an-1=12en-1+14en-2, i.e., errors at each step are less than a weighted average of those in previous two steps, with e1=e0=1. Is this a convergent approximation? Present both an analytical solution, and a numerical experiment.