# Question: write a program that receives a real number in decimal...

###### Question details

Write a program that receives a real number in decimal (base 10) and converts it into binary.

• You must implement the algorithm discussed in Chapter 1

Input: x ∈ (0, 1), integer β ≥ 2 and c0 = x;

i = 0;

while ci ̸= 0 .and. i ≤ Imax do

i = i + 1;

bi = (βci−1)I ;

ci = (βci−1)F ;

end while

Output: x = ( . b1b2b3 . . . bi)β = ∑i k=1 bkβ −k .

. • You may not use libraries or built-in functions (e.g., Double.toHexString(...) in Java or ”{0:b}”.format(...) in Python)

2. The following algorithm (attributed to Clever Moler) estimates machine precision (eps): a = 4.0/3.0; b = a − 1.0; c = b + b + b; eps = abs(c − 1.0). Implement the program twice with single and double precision variable types and report the value of eps for both single and double precision.

3. a) write a program to compute an approximate value for the derivative of a function using the finite difference formula f ′ (x) ≈ f(x + h) − f(x) h . (2) Test your program using the function sin(x) for x = 1. Determine the error by comparing with the built-in function cos(x). Plot the magnitude of the error as a function of h, for h = 1 2 , 1 4 , 1 8 , . . . You should use a log scale for h and the magnitude of the error. Is there a minimum value for the magnitude of the error? b) (5 points) Check if the corresponding value of h to the minimum value for the magnitude of the error can be approximately equal to √ eps ? Why?