Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
round-off error

Subject: round-off error

From: Grzegorz Knor

Date: 20 Apr, 2011 11:49:06

Message: 1 of 3

Hi!

Is there a way to avoid this type of errors in matlab:

p = poly([1 1 1 1 1 1 1])
p =
     1 -7 21 -35 35 -21 7 -1
r = roots(p)
r =
   1.0090
   1.0056 + 0.0070i
   1.0056 - 0.0070i
   0.9980 + 0.0088i
   0.9980 - 0.0088i
   0.9919 + 0.0039i
   0.9919 - 0.0039i

?

Grzegorz

Subject: round-off error

From: Steven_Lord

Date: 20 Apr, 2011 13:20:22

Message: 2 of 3



"Grzegorz Knor" <gknor@o2.pl> wrote in message
news:iomh7h$j76$1@fred.mathworks.com...
> Hi!
>
> Is there a way to avoid this type of errors in matlab:
>
> p = poly([1 1 1 1 1 1 1])
> p =
> 1 -7 21 -35 35 -21 7 -1
> r = roots(p)
> r =
> 1.0090 1.0056 + 0.0070i
> 1.0056 - 0.0070i
> 0.9980 + 0.0088i
> 0.9980 - 0.0088i
> 0.9919 + 0.0039i
> 0.9919 - 0.0039i

Not without using an arbitrary precision package like Symbolic Math Toolbox.

Welcome to the world of numerical analysis.

You might want to read the first question in the Mathematics section of the
FAQ for more information about floating-point arithmetic.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: round-off error

From: Roger Stafford

Date: 20 Apr, 2011 17:03:05

Message: 3 of 3

"Grzegorz Knor" wrote in message <iomh7h$j76$1@fred.mathworks.com>...
> Hi!
>
> Is there a way to avoid this type of errors in matlab:
>
> p = poly([1 1 1 1 1 1 1])
> p =
> 1 -7 21 -35 35 -21 7 -1
> r = roots(p)
> r =
> 1.0090
> 1.0056 + 0.0070i
> 1.0056 - 0.0070i
> 0.9980 + 0.0088i
> 0.9980 - 0.0088i
> 0.9919 + 0.0039i
> 0.9919 - 0.0039i
>
> ?
>
> Grzegorz
- - - - - - - - - -
  From a numerical analysis point of view you have given 'roots' a difficult problem, Grzegorz. Your polynomial is y = (x-1)^7 which means that if y differs from 0 by only 1.0e-16, the corresponding x would differ from 1 by a whopping big 0.005, which as you see is of the order of error you are experiencing. Since 'roots' must use the polynomial form to compute y, such errors in y are inevitable.

  Suppose your roots were all to be pi as in y = (x-pi)^7. If you expand this polynomial to powers of x, and round each of the resulting coefficients to the 53-bit accuracy of which your computer is capable, then I believe you will find that the theoretical roots of infinite precision for such a "rounded" polynomial would depart from pi by very substantial amounts, of the same order of magnitude that you have observed in your trial - that is, more or less in the third decimal place. It is a problem that is inherent in the mathematical nature of finding repeated polynomial roots.

  Of course you might argue that in your particular case with all roots equal to a common integer, the polynomial coefficients would necessarily all be exact integers also so there should be no reason to make any errors whatever. I am afraid 'roots' is not so sophisticated as to be able to take advantage of such a special situation as that.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us