Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using C language [25 marks) In floating-point arithmetic, the order in which numbers are added mat- ters. There is a famous algorithm originally due to

image text in transcribed

using C language

[25 marks) In floating-point arithmetic, the order in which numbers are added mat- ters. There is a famous algorithm originally due to Kahan (1965) called compensated summation that estimates the error produced when summing two floating-point num- bers and accumulates this error estimate during the computation. It is based on the observation that the round-off error in the sum of two floating-point numbers can be estimated by subtracting one of the numbers from the sum. Let a and b be two numbers such that al > bl. Their exact sum is s= a +b= s + e. Let a = a1 + a2 and b = b; + b2, where az and b, are determined by the significance overlap of the numbers. Then = a1 + a2 + b). Now - a=bi, and thus we can get an estimate of the error from ( - a) - b= -b2 = -e. Generate an array of one million random numbers in single precision from a uniform distribution on [0,1]. Cast the numbers as double precision and sum them in the order in which they were generated. We will take this as the reference solution, i.e., a highly accurate estimate of the exact solution. Sum the numbers in the order in which they were generated and compute the error in the sum. Sort the numbers in ascending order, sum them, and compute the error in the sum. Sum the numbers using compensated summation and compute the error in the sum. Comment on the performance of the different methods for computing the sum. [25 marks) In floating-point arithmetic, the order in which numbers are added mat- ters. There is a famous algorithm originally due to Kahan (1965) called compensated summation that estimates the error produced when summing two floating-point num- bers and accumulates this error estimate during the computation. It is based on the observation that the round-off error in the sum of two floating-point numbers can be estimated by subtracting one of the numbers from the sum. Let a and b be two numbers such that al > bl. Their exact sum is s= a +b= s + e. Let a = a1 + a2 and b = b; + b2, where az and b, are determined by the significance overlap of the numbers. Then = a1 + a2 + b). Now - a=bi, and thus we can get an estimate of the error from ( - a) - b= -b2 = -e. Generate an array of one million random numbers in single precision from a uniform distribution on [0,1]. Cast the numbers as double precision and sum them in the order in which they were generated. We will take this as the reference solution, i.e., a highly accurate estimate of the exact solution. Sum the numbers in the order in which they were generated and compute the error in the sum. Sort the numbers in ascending order, sum them, and compute the error in the sum. Sum the numbers using compensated summation and compute the error in the sum. Comment on the performance of the different methods for computing the sum

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions