Does roots have an issue with large coefficients?

I have noticed that the values I obtain with roots are different than those that I find with vpasolve (closer to expected).

 Accepted Answer

Why would you be even remotely surprised? Roots works in DOUBLE precision arithmetic. Of course big coefficients can be a problem, because floating point arithmetic will be involved.
For example, see how easy it is to trip roots up:
syms x
P = expand((x-1)*(x - 1e10 + i)*(x - 1e10 - i))
P =
x^3 - 20000000001*x^2 + 100000000020000000001*x - 100000000000000000001
vpasolve(P==0)
ans =
1.0
10000000000.0 - 1.0i
10000000000.0 + 1.0i
roots([1 -20000000001 100000000020000000001 -100000000000000000001])
ans =
1e+10 + 147.33i
1e+10 - 147.33i
1 + 0i
That is not always the case of course. So if I just pick some set of large random coefficients, roots will probably do ok.
format long g
C = [1,rand(1,4)*1e15]
C =
1 184342604119778 162956226687924 75790019563777 436978740562955
roots(C)
ans =
-184342604119778 + 0i
-1.57673059792158 + 0i
0.346372446939334 + 1.17619511597991i
0.346372446939334 - 1.17619511597991i
vpasolve(x^4 + C(2)*x^3 + C(3)*x^2 + C(4)*x + C(5) == 0)
ans =
-184342604119777.5535142959570983444967693
-1.576730598062861967656730050376918994998
0.3463724470099801560767496588525252066424 - 1.176195116160874500159456451136807293786i
0.3463724470099801560767496588525252066424 + 1.176195116160874500159456451136807293786i

2 Comments

Thank you, I wanted to confirm this point as I was obtaining positive real parts instead of negative real parts when I tried to obtain roots of Hurwitz polynomials with large coefficients.
Could you accept John's answer?

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!