# COMP350 Numerical Computing Assignment #2: Floating point in C, overflow and underflow, numerical cancellation Solved

30.00 \$

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . ` zip` solution files instantly, after Payment

## Description

1. (5 points) Write a C program to find the smallest positive integer x such that the floating point expression

1 âŠ˜ (1 âŠ˜ x)

is not equal to x, using single precision. Make sure that the variable x has type float, and assign the value of the expression 1 âŠ˜ x to a float variable before doing the other division operation. Repeat with double precision.

1. (5 points) A calculus student was asked to determine limnâ†’âˆž xn, where xn = (100n)/n!. He wrote a C program in single precision to evaluate xn by using

x1 = 100,Â Â Â Â Â Â  xn = 100xnâˆ’1/n,Â Â Â Â Â Â Â Â Â  n = 2,3,…,70.

The numbers printed became ever larger and finally became âˆž. So the student concluded that limnâ†’âˆž xn = âˆž. Please write a C program in single precision to verify the studentâ€™s observation. The studentâ€™s conclusion is actually wrong. What is the problem with his program?

Bonus (2 points): Can you rewrite a C program to evaluate xn so that you can make a right conclusion about limnâ†’âˆž xn ?

1. (10 points) In 250 B.C.E., the Greek mathematician Archimedes estimated the number Ï€ as follows. He looked as a circle with diameter 1, hence circumference Ï€. Inside the circle he inscribed a square; see the following figure. The perimeter of the square is smaller than the

circumference of the circle, and so it is a lower bound for Ï€. Archimedes then considered an inscribed octagon, 16-gon, etc., each time doubling the number of sides of the inscribed polygon, and producing ever better estimates for Ï€. Using 96-sided inscribed and circumscribed polygons, he was able to show that 223/71 < Ï€ < 22/7. There is a recursive formula for these estimates. Let pn be the perimeter of the inscribed polygon with 2n sides. Then p2 is the perimeter of the inscribed square, p2 = 2âˆš2. In general

.

• Write a program to compute pn for n = 3,4,…,35 in double precision by using the formula. Explain your results.
• Improve the formula to avoid the difficulty with it. Compute pn for n = 3,4,…,35 by your new formula in double precision. Comment on your results.

Note: Your program should not do unnecessary computation.

• a2-3.zip