MATLAB: How to handle rounding error

roundoff error

I want to check if the roots of a polynomial have absolute value <= 1. tried to handle roundoff error by using eps, but only eps does not work as follows:
p=[1 1 0 0 1 0 0 1 1];
abs(roots(p)) <= 1+eps
abs(roots(p)) <= 1+8*eps
The result:
ans =
0
0
0
0
0
0
1
1
ans =
1
1
1
1
1
1
1
1
So in usual, how should I write a code? Should I use something like 100*eps?

Best Answer

By the binomial theorem,
(a+b)^n = a^n + n*a^(n-1)*b + n*(n-1)/2 * a^(n-2)*b^2 + more terms
when b is very small compared to a, then b^2 will be even smaller, and when dealing with floating-point-roundoff-small indicates a term that can probably be neglected unless a is relatively large. So with round-off taken into consideration,
(a+b)^n <=> a^n + n*a^(n-1)*b
and when a is 1, then this naturally simplifies to 1 + n*b
You had an 8th order polynomial (your vector was length 9), so your n=8, and that is the source of your 8 for 8*eps
Related Question