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

$25

File Name: COMP350_Numerical_Computing_Assignment_#2:_Floating_point_in_C,_overflow_and_underflow,_numerical_cancellation.zip
File Size: 1036.2 KB

SKU: [Solved] COMP350 Numerical Computing Assignment #2: Floating point in C, overflow and underflow, numerical cancellation Category: Tag:
5/5 - (1 vote)

Submit your assignment including your code through myCourses.

  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 = 100xn1/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 students observation. The students 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 = 22. 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.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] COMP350 Numerical Computing Assignment #2: Floating point in C, overflow and underflow, numerical cancellation
$25