Docsity

Floating Point Numbers and Fixed-Point Iteration Scheme Solutions - Prof. Aldo Ferri, Exams of Computer Science

Toggle sidebar
bg1
1
ME2016D, Fall 2008, Dr. Ferri Name: _____Solution_______
Test 1, September 17
This is a closed-book, closed-notes test. You are allowed to refer to a single 8.5x11 inch page of
notes. The sheet must be single-sided and must be handwritten. Show all of your work to receive
credit.
Honor Pledge:
On my honor, I pledge that I have neither given nor received any inappropriate aid in the
preparation of this test.
_______________________________
Signature
Problem 1 (20) ____20____
Problem 2 (20) _____20____
Problem 3 (20) _____20____
Problem 4 (20) _____20____
Total (80) _________80____
pf3
pf4
pf5

Partial preview of the text

Download Floating Point Numbers and Fixed-Point Iteration Scheme Solutions - Prof. Aldo Ferri and more Exams Computer Science in PDF only on Docsity!

ME2016D, Fall 2008, Dr. Ferri Name: _____ Solution _______ Test 1, September 17

This is a closed-book, closed-notes test. You are allowed to refer to a single 8.5x11 inch page of notes. The sheet must be single-sided and must be handwritten. Show all of your work to receive credit.

Honor Pledge: On my honor, I pledge that I have neither given nor received any inappropriate aid in the preparation of this test.

_______________________________

Signature

Problem 1 (20) ____ 20 ____

Problem 2 (20) _____ 20 ____

Problem 3 (20) _____ 20 ____

Problem 4 (20) _____ 20 ____

Total (80) _________ 80 ____

Consider a hypothetical computer that uses 10 bits to represent floating-point numbers. The format of this representation is

x = −( 1) (1. s^ f )2(^ c^ − b )

where s is the sign bit, f is represented with 5 bits, c by 4 bits, and b is a bias. Answer the questions below, showing your work. (a) What is the smallest positive number greater than zero that can be represented on this computer? You may leave your answer in terms of powers of 2. (b) Give the base-10 numbers given by the two, 10-bit registers below:

(c) What is the smallest positive number ε such that 1+ε > 1? (d) The textbook uses a slightly different scheme for storing floating point numbers than the one we used (similar to the IEEE standard.) Specifically, the text uses a format of

x = −( 1) (0. s^ m )2 e

where the first digit of the mantissa m must be 1 and the first bit of the exponent field is a sign bit. What is the advantage, if any, of the IEEE standard?

Solution:

(a) Since k = 4, the bias is given by b = 2 k −^1 − 1 = 23 − 1 = 7. The smallest number is associated with a characteristic of c = (0 0 0 1) 2 =1 and a fraction of f = (0 0 0 0 0) 2. Thus the smallest positive number is

1 2 1 7 2 6 1 0. 64

× −^ = − = =

(b) The first number has c = (0 1 0 1) 2 = 5, so

5 7 2 1

num = × −^ = − = =

The second number has the same c , but is incremented in f :

5 7 5 2 2 2 1

num = × −^ = num + −^ − = + =

(c) For this problem, n = 5, thus machine epsilon is given by: 5

ε = −^ n^ = − = =

(d) In comparison to the text convention, the IEEE standard is able to save two bits: 1 sign-bit in the exponent and 1 bit in the mantissa.

Consider the function f ( ) x = xex.

(a) Derive a 3-term Taylor series expansion for f(x) about the point a = 1. (b) In terms of an unknown number ξ , give an expression for the remainder term, R 2.

(c) If x = 1 + h , where h is a small step size, what is the order of the truncation error in your Taylor series of part (a) for f(1+h)? (d) If the size of h is cut in half, by what factor should the truncation error change?

Solution

2 2

f x = f a + f ′^ a x − a + f ′′ a x − a + R

With f ( ) x = x ex and a = 1, we have

f ( ) a = (1) e^1 = e , f ′( ) x = ex + x e x → f ′( ) a = 2 e ,

f ′′( )^ x = e x^ + e x^ + x ex → f ′′( ) a = 3 e , f ′′′( )^ x = 3 e x^ + x e x^ = (3 + x e ) x

(2 1) (2 1) (3) 3 2

R = f +^ ξ x − a + = f ξ x −

Thus, a 3-term Taylor series is given by

( ) 2 ( 1) 3 ( 1)^2

e f x ≈ e + e x − + x −

with remainder 3 2

e x R

+ ξ^ ξ −

e f + h = e + eh + h + O h Thus, the truncation error is order O(h^3 ). If the size

of h is cut in half, the truncation error should drop by a factor of 8.

A heavy weight must be supported on a spring having a nonlinear stiffness. The relationship governing the compression of the spring and the weight is

2 W = k x 1 + k (^) 2 exp( bx )

where k 1 , k 2 , and b are constants and W is the weight. We wish to find a relationship between the compression x and the parameter b. In particular, you must write a Matlab script that takes k 1 = 1, k 2 = 3 and W = 10 and considers a range of values of b from 0 to 10 in steps of 0.1. For each value of b , your program must solve for the corresponding value of x using the Matlab function fzero. Finally, your program must generate a plot of compression x vs b. Your program should make use of anonymous functions and should use an appropriate starting guess for each application of the function fzero****.

Solution

bvec = 0:0.1:10; L = length(bvec); k1 = 1; k2 = 3; W = 10; xvec = zeros(1,L); x0 = (W - k2)/k1;

for i = 1:L; b = bvec(i); f = @(x) k1x + k2exp(b*x.^2) - W; x0 = fzero(f,x0); xvec(i) = x0; end

plot(bvec,xvec,'linewidth',2) xlabel('b') ylabel('x') grid

W

x

spring

0 2 4 6 8 10

0

2

4

6

8

b

Produces the graph x