The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Precision question
Replies: 1   Last Post: Oct 21, 2011 3:45 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Roger Stafford

Posts: 5,929
Registered: 12/7/04
Re: Precision question
Posted: Oct 21, 2011 3:45 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"" <> wrote in message <>...
> I have three algorithms to calculate the inner product of vector
> A(i,j) and vector V for M x N times.
> With the line A = round(A), B1 = B2 = B3.
> Without the line A = round(A);, B1 != B2, B2 = B3.
> Is this a precision error?
> Which one is correct?
> ........

- - - - - - - - -
When you take the sum of terms (as in an inner product,) if the quantities involved have one-bits in their binary representations occurring at or near their least significant bit positions, the results will generally be subject to round off errors. In this case the order in which the additions are performed may affect the result, though of course only in these least bits.

In other words, with such quantities, the associative law of addition is not strictly adhered to, so that (a+b)+c does not always give exactly the same result as a+(b+c). Try this on your computer:

a = 3/14; b = 3/14; c = 15/14;
(a+b)+c == a+(b+c)

This would presumably account for your results when the 'rand' function is used without doing a 'round' on A. The matrix multiply operation in algorithm 1 apparently performs its additions in a different order than is used in the element-by-element multiplication followed by the 'sum' function of algorithms 2 and 3.

The same comment applies to a series of successive multiplications. The associative law of multiplication does not always hold so that the ordering of multiplications would affect the result.

You must always be prepared for differing results in the least few bits of an answer when different, though supposedly mathematically equivalent, series of arithmetic operations are performed, due to differences in rounding errors.

Roger Stafford

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.