Why do I recieve an "error using ==>eig NaN or Inf prevents convergence" error when using the ROOTS function?

2 views (last 30 days)
I am using the ROOTS function to find the roots of a 6th degree polynomial. When ROOTS is called, I receive the following error message:
??? Error using ==> eig
NaN or Inf prevents convergence.
Error in ==> roots at 42
r = [r;eig(a)];

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
When operating in the class 'SINGLE', the largest floating point number representable on the computer is 3.4028e+038 which is given by 'REALMAX('SINGLE')'. While calculating the roots of the given polynomial, one of the coefficients exceeds this largest floating point number and overflows to Inf. This results in the "error using ==>eig NaN or Inf prevents convergence" message being reported.
1. If it is required to work in single precision numbers, one workaround would be to convert the coefficients of the polynomial to double, find the roots and convert them back to single class as indicated below:
r = single(roots(double(c))) % where 'c' is a row vector consisting of the coefficients of the polynomial in single class
The other workarounds involve using functions other than ROOTS to find the roots of a polynomial as listed below:
2. Use the SOLVE function (listed under Symbolic Math Toolbox):
y = solve([ x.^6 x.^5 x.^4 x.^3 x.^2 x.^1 1 ]*c')
3. Use the FMINSEARCH function (listed under Optimization Toolbox) to find the minima of the square of the polynomial:
y = fminsearch(@(x) ([ x.^6 x.^5 x.^4 x.^3 x.^2 x.^1 1 ]*c').^2 , 1 )
4. Other options include using the FSOLVE or FZERO functions to find the minima based on the objective function.

More Answers (0)

Categories

Find more on Polynomials in Help Center and File Exchange

Products


Release

R14SP2

Community Treasure Hunt

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

Start Hunting!