Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Prepare a MATLAB/Octave script that sums n random, single-precision floating-point numbers xi , uniformly distributed in the interval [0, 1]. Sum the numbers in each

Prepare a MATLAB/Octave script that sums n random, single-precision floating-point numbers xi , uniformly distributed in the interval [0, 1]. Sum the numbers in each of the following ways (using single-precision variables unless specifically indicated otherwise): (a) Sum the numbers in the order in which they were generated, using a double-precision variable to accumulate the sum. Use a loop to do the summation and not the builtin function. (b) Sum the numbers in the order in which they were generated, this time using a single-precision accumulator. Use a loop to do the summation and not the builtin function. (c) Use the following compensated summation algorithm, again using only single precision, to sum the numbers in the order in which they were generated: s = 0 c = 0 for i = 1 to n do 1 y = xi c t = s + y c = (t s) y s = t end for (d) Sum the numbers in order of increasing magnitude (using the builtin sort function). Use a loop to do the summation (after sorting the numbers) and not the builtin function. (e) Sum the numbers in decreasing magnitude (reversing the order obtained in the previous part). Use a loop to do the summation and not the builtin function. Once you check for correctness, extend the previous program to answer the following: (i) Experiment with different values of n and chart your results. Note that you may need to use fairly large values of n to see substantial differences. (ii) How do the methods rank in terms of accuracy, and why? You can use the result of the builtin function sum as the true value. Do not use the builtin function for (iii) How do the methods compare in cost? Time the routines for a large n and provide a comparison. (iv) Briefly explain how/why the compensated summation algorithm works.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions