Docsity

Binary Representation - Numerical Analysis | Assignment | MCS 471, Assignments of Mathematical Methods for Numerical Analysis and Optimization

Toggle sidebar
bg1
MCS 471 Selected Solutions
1Binary Representation
[i] 27 = 1 ×16 + 1 ×8+0×4+1×2+1×1 = 11011
[ii] 15.140625 = 1 ×8 + 1 ×4 + 1 ×2 + 1 ×1 + 0 ×1/2 + 0 ×1/4 + 1 ×1/8 + 0 ×1/16 +
0×1/32 + 1 ×1/64 = 1111.001001
2Floating Point Arithmetic For these exercises assume that numbers are expressed in the
form r=±0.d1d2....dk×10t, with k= 5 and t∈[−5,5]). The diare integers in [0,9].
[i] The largest number in this system is 0.99999×105, the smallest (nonzero) in magnitude
is 0.00001 ×10−5
[ii] If chopping is used (rather than rounding), the number .12300 ×103represents what
interval of real numbers.
The next number below 0.12300 ×103is 0.12299 ×103, the next higher is 0.12301 ×103. When
chopping is used the interval [.12300 ×103,0.12301 ×103)is represented by 0.12300 ×103.
Similarly if rounding is used the interval is [.122995 ×103,0.123005 ×102)
3Bisection: Calculate √2 by hand to five decimal places using bisection. Show your compu-
tation in a table of the successive intervals.
Use the function f(x) = x2−2. Begin with an interval containing √2, for example (1,2).
Continue halving the interval until the interval has width less than 10−5, here it will take 18
intervals to get an interval of width 2−17 ≈8×10−6.
4Fixed Point Algorithm
[i] Show that the fixed point algorithm converges locally when |f0(x)|< k < 1 in the
neighborhood of the fixed point.
Solution
xn+1−p=f(xn)−p=f(p+xn−p)−p=f(p)+f0(ξ)(xn−p) = p+f0(ξ)(xn−p)−p=f0(ξ)(xn−p)
Here ξis a point between xnand p. Since |f0|< k near the fixed point we get
En+1 ≤kEn
Iterating this formula, En≤knE0, thus the error goes to zero as n→ ∞
[ii] Under what circumstance will the fixed point iteration converge faster than linearly.
f0(p) = 0
1
pf3
pf4
pf5
pf8

Partial preview of the text

Download Binary Representation - Numerical Analysis | Assignment | MCS 471 and more Assignments Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

1 Binary Representation

[i] 27 = 1 × 16 + 1 × 8 + 0 × 4 + 1 × 2 + 1 × 1 = 11011

[ii] 15.140625 = 1 × 8 + 1 × 4 + 1 × 2 + 1 × 1 + 0 × 1 /2 + 0 × 1 /4 + 1 × 1 /8 + 0 × 1 /16 + 0 × 1 /32 + 1 × 1 /64 = 1111. 001001

2 Floating Point Arithmetic For these exercises assume that numbers are expressed in the form r = ± 0 .d 1 d 2 ....dk × 10 t, with k = 5 and t ∈ [− 5 , 5]). The di are integers in [0, 9].

[i] The largest number in this system is 0. 99999 × 105 , the smallest (nonzero) in magnitude is 0. 00001 × 10 −^5

[ii] If chopping is used (rather than rounding), the number. 12300 × 103 represents what interval of real numbers.

The next number below 0. 12300 × 103 is 0. 12299 × 103 , the next higher is 0. 12301 × 103. When chopping is used the interval [. 12300 × 103 , 0. 12301 × 103 ) is represented by 0. 12300 × 103. Similarly if rounding is used the interval is [. 122995 × 103 , 0. 123005 × 102 )

3 Bisection: Calculate

2 by hand to five decimal places using bisection. Show your compu- tation in a table of the successive intervals.

Use the function f (x) = x^2 − 2. Begin with an interval containing

2 , for example (1, 2). Continue halving the interval until the interval has width less than 10 −^5 , here it will take 18 intervals to get an interval of width 2 −^17 ≈ 8 × 10 −^6.

4 Fixed Point Algorithm

[i] Show that the fixed point algorithm converges locally when |f ′(x)| < k < 1 in the neighborhood of the fixed point.

Solution

xn+1−p = f (xn)−p = f (p+xn−p)−p = f (p)+f ′(ξ)(xn−p) = p+f ′(ξ)(xn−p)−p = f ′(ξ)(xn−p)

Here ξ is a point between xn and p. Since |f ′| < k near the fixed point we get

En+1 ≤ kEn

Iterating this formula, En ≤ knE 0 , thus the error goes to zero as n → ∞

[ii] Under what circumstance will the fixed point iteration converge faster than linearly.

f ′(p) = 0

[iii] Consider the fixed point algorithm xi+1 = 1/3(x^2 i + 2) as a method to find the roots of x^2 − 3 x + 2. Is this iteration locally convergent near x = 2? Near x = 1?

Take derivatives at the fixed point. The algorithm converges when |f ′(p)| < 1.

[iv] Write your own fixed point algorithm to find the roots of x^2 − 3 x + 2, such that it converges at x = 2.

Example: xn+1 =

3 xn − 2 , so that f ′(2) = 3/ 4

5 Newton’s Method [i] Show that Newton’s method converges quadratically to a root p of a twice differentiable function f , if f ′(p) 6 = 0 and f ′′(p) 6 = 0.

Either Taylor expand and collect terms, or use knowledge of the fixed point method:

Consider the fixed point method xn+1 = g(xn), with g(xn) = xn − (^) ff ′^ ((xxnn)). Fixed point methods converge quadratically when g′(p) = 0. Here g′(p) = 1 − f^

′(p) f ′(p) +^

f (p)f ′′(p) f ′(p)^2.^ Since^ f^ (p) = 0, g′(p) = 0

6 Newton’s Method Does Newton’s method ever converge faster than quadratically? Explain by writing the ap- propriate power series expansions. What does this imply about the associated fixed point method? Taylor expanding and collecting terms yields

(xn+1 − p) =

f ′′(p) 2 f ′(p) (xn − p)^2 + O((xn − p)^3 )

Thus when f ′′(p) = 0 this method converges at least cubically.

16 Solving Linear Systems Find a solution to the system  

x y z

There are many solutions. For arbitrary y, a solution is

x =

y −y

17 Counting Operations: Evaluate

[i]

∑n i=1(1^ −^3 i^ +^ n) =^

∑n i=1 1 −^3

∑n i=1 i^ +^ n^

∑n i=1 1 =^ n^ −^3

n(n+1) 2 +^ n

2

[ii]

∑n i=1 2 i

(^2) − 5 = 2 ∑n i=1 i

(^2) − 5 = 2 n(2n+1)(n+1) 6 −^5

21 Gauss-Seidel Method For what z does the Gauss-Seidel method converge when applied to M. M =

− 1 z

Find the eigenvalues of the iteration matrix M 1 = −(D + L)−^1 U

M 1 = −

0 − 2 /z

Here |λ 1 | = 0 and |λ 2 | = (^) |^2 z| which is less than one when |z| > 2.

  1. Consider the matrices,

A 1 =

A 2 =

[i] Are these matrices diagonal dominant? For which matrix is the ratio of the off-diagonal entries to the diagonal entries smaller? For which matrix do you think the Jacobi Method con- verges faster?

Both matrices are diagonal dominant. The largest ratio of the off diagonal entries to the diag- onal ones is − 3 / 4 for A 2 and − 1 / 2 for A 1. One might think that the Jacobi method converges faster for A 1 (this intuition turns out to be incorrect).

[ii] If the Jacobi method is written xk+1^ = M xk^ + f , calculate M for both A 1 and A 2. Compute the eigenvalues of each M.

The matrices are

M 1 =

and M 2 =

The eigenvalues of M 1 are λ = ± 1 / 2 for M 2 they are λ = ± 1 / 4

[iii] The spectral radius ρ(M ) is the magnitude of the largest eigenvalue of M, find the spectral radius of each M. For which matrix does the Jacobi method converges faster?

ρ(M 1 ) = 1/ 2 and ρ(M 2 ) = 1/ 4 so the Jacobi method converges faster for matrix A 2.

22 S.O.R. Consider the matrix

S =

1 ρ −ρ 1

[i] For what ρ does the Gauss-Seidel method converge for this matrix.

Find the eigenvalues of M = −(D + L)−^1 U. They have magnitude |λ| = ρ^2 and 0 , so the Gauss-Seidel method converges when |ρ| < 1.

[ii] For which ω does the S.O.R. method converge fastest.

Again we must find the eigenvalues of the iterative matrix Mω = (D + ωL)−^1 ((1 − ω)D − ωU ). We are only concerned with the magnitude. Defining

b = ω^2 ρ^2 − 2(1 − ω) c = 4(1 − ω)^2

|λ|^2 =

4

b^2 ± 2 b

b^2 − c + b^2 − c

, b^2 − c > 0; 1 4

b^2 − b^2 + c

, b^2 − c < 0. One way to find the minimum of g(ω, ρ) = max(|λ 1 |^2 , |λ 2 |^2 ) is to plot it, and notice that the minimum for each ρ is where the derivative with respect to ρ is discontinuous. This is where b^2 − c = 0. Solving this equation gives ω as a function of ρ.

23 Interpolation: Values of a function are known at 5 x values, xi = {− 2 , 0 , 3 , 5 , 7 }, where it takes values f (xi) = { 3 , 0 , 3 , − 1 , 2 }. Find the polynomial of degree 4 which pass through these points using the Lagrange polynomial and Newton’s divided difference.

Lagrange Polynomial:

L 1 (x) =

(x − 0)(x − 3)(x − 5)(x − 7) (− 2 − 0)(− 2 − 3)(− 2 − 5)(− 2 − 7)

L 2 (x) =

(x + 2)(x − 3)(x − 5)(x − 7) (0 + 2)(0 − 3)(0 − 5)(0 − 7)

L 3 (x) =

(x + 2)(x − 0)(x − 5)(x − 7) (3 + 2)(3)(3 − 5)(3 − 7) L 4 (x) =

(x + 2)(x − 0)(x − 3)(x − 7) (5 + 2)(5 − 0)(5 − 3)(5 − 7)

L 5 (x) =

(x + 2)(x − 0)(x − 3)(x − 5) (7 + 2)(7)(7 − 3)(7 − 5) P (x) = 3L 1 (x) + 0L 2 (x) + 3L 3 (x) − 1 L 4 (x) + 2L 5 (x) Newton’s Divided Difference Polynomial

F [−2] = 3

F [− 2 , 0] =

= − 3 / 2 , F [0, 3] = 1, F [3, 5] = − 2 , F [5, 7] = 3/ 2

F [− 2 , 0 , 3] =

= 1/ 2 , F [0, 3 , 5] =

= − 3 / 5 , F [3, 5 , 7] =

F [− 2 , 0 , 3 , 5] =

= − 11 / 70 , F [0, 3 , 5 , 7] =

F [− 2 , 0 , 3 , 5 , 7] =

P (x) = F [−2] + F [− 2 , 0](x + 2) + F [− 2 , 0 , 3](x + 2)x + F [− 2 , 0 , 3 , 5](x + 2)x(x − 3)(x − 5) + ...

... + F [− 2 , 0 , 3 , 5 , 7](x + 2)x(x − 3)(x − 5)(x − 7)

[i] Find the best step size for centered/leapfrog difference

f (^) c′(x) ≡

f (x + h) − f (x − h) 2 h Just as for forward difference if we Taylor expand everything with multiples of (1 ± ceps), we get a term proportionate to eps/h, so the leading terms in the error are now Error(h) = c 1 epsh + c 2 h^2 + ... This error function has a minimum at h proportionate to (eps)^1 /^3

[ii] If we use the best step size for each method, which has smaller error (truncation and precision)?

Forward difference using h ∼ eps^1 /^2 has error proportionate to eps^1 /^2 , centered difference with h ∼ eps^1 /^3 has error proportionate to eps^2 /^3. Since eps < 1 , we know that eps^2 /^3 < eps^1 /^2 , thus centered difference has smaller error.

31 In class we derived the following approximation of the first derivative

f (^) R′(x, h) ≡ 4 f (x + h/2) − 3 f (x) − f (x + h) h This approximation acts on step size xi+1 − xi = h/2. [i] Rewrite the method so that it can be used on discretization with step size h.

The new method is f (^) R,′ 2 (x, h) ≡

4 f (x + h) − 3 f (x) − f (x + 2h) 2 h

[ii] Find the truncation error of this method. Show that this method is second order, O(h^2 ), and find the coefficient of the h^2 term.

Just Taylor expand everything.

32 Consider a general approximation B(x, h) to a function b(x) with truncation error

E = B(x, h) − b(x) = c 1 h + c 2 h^2

[i] Use Richardson Extrapolation to find a second order approximation to b(x).

Look at B(x, h/2). Defining B 1 (x, h) = 2B(x, h/2) − B(x, h) gives an approximation has no O(h) term in the error.

[ii] Use Richardson Extrapolation again to get an exact approximation for b(x) in terms of B, (one with no truncation error).

Same idea as before, look at B 1 (x, h/2). Now defining B 2 (x, h) = 4 B^1 (x,h/2) 3 −B^1 (x,h) cancels the O(h^2 ) error. Since there are no higher order terms in the original error, this formula is exact.

34 Find the coefficients ai of a quadrature rule

f (x)dx =

aif (xi) which uses cubics to ap- proximate f (x) on the interval (xi, xi+3).

Here use the lagrange polynomials to interpolate f (x), on the interval (xi, xi+3), so that

P (x) = f (xi) (x − xi+1)(x − xi+2)(x − xi+3) − 6 h^3

  • f (xi+1) (x − xi)(x − xi+2)(x − xi+3) 2 h^3

+f (xi+2)

(x − xi)(x − xi+1)(x − xi+3) − 2 h^3

  • f (xi+3)

(x − xi)(x − xi+1)(x − xi+2) 6 h^3

Integrating this over (xi, xi+3) ∫ (^) xi+

xi

P (x) = h

f (xi) +

f (xi+1)

f (xi+2) +

f (xi+3)

Now to get the formula for an interval (a,b) we have to take the union of such subintervals, and sum the above formula ∫ (^) b

a

f (x) =

h

f (a) + f (b) +

3 f (x 3 i− 2 ) + 3f (x 3 i− 1 ) + 2f (x 3 i)

35 In class we derived the gaussian quadrature points xi and coefficients ai when n = 2. Derive the weights ai and the points xi for a gaussian quadrature scheme when n = 3.

Here we have three points (x 1 , x 2 , x 3 ) and three weights (a 1 , a 2 , a 3 ). For gaussian quadrature we impose that our scheme exactly integrates polynomials of degree less than 2 n − 1 , here this means up to degree 5 ∫ (^1)

− 1

1 = 2 = a 1 + a 2 + a 3 ∫ (^1)

− 1

x = 0 = a 1 x 1 + a 2 x 2 + a 3 x 3 ∫ (^1)

− 1

x^2 = 2 /3 = a 1 x^21 + a 2 x^22 + a 3 x^23 ∫ (^1)

− 1

x^3 = 0 = a 1 x^31 + a 2 x^32 + a 3 x^33 ∫ (^1)

− 1

x^4 = 2 /5 = a 1 x^41 + a 2 x^42 + a 3 x^43 ∫ (^1)

− 1

x^5 = 0 = a 1 x^51 + a 2 x^52 + a 3 x^53

Looking for a symmetric solutions (and some manipulation) gives a 1 = a 3 = 5/ 9 , a 2 = 8/ 9 , x 2 = 0, and x 3 = −x 1 =