Improved algorithms for finding the roots (direct method for first order quadratic, cubic and Quartic) are used for low order equations.
Fadeev algorithm for finding the characteristic polynomial is implemented to ensure high accuracy.
These files can be used as a replacement of original MATLAB files.
PDFversion of technical note is included to show the algorithm and examples.
MATLAB release
MATLAB 6.1 (R12.1)
Other requirements
Can be used in any version of MATLAB, although tested under 6.1
See
u = [2.0000 0 0.0625 -0.0187]
roots(u)
roots1(u)
20 Nov 2006
Santhosh Kodipaka
bug]: Try this:
% roots1.m is kind of buggy here
P = [ 0.9159 0.6020 0.2536 0.8735 0.5134];
roots1( P )
roots(P )
04 Aug 2006
Ryan Bennink
The algorithm switches to matlab's less accurate ROOTS function in the case of complex coefficients. If you take the switch out, the algorithms are not quite suitable for complex numbers because they don't always use the right sign of the root. The code below, which replaces lines 50 and 51, yields the correct sign in all cases:
if abs(rr(1))>abs(rr(2))
u=rr(1)^(1/3);
else
u=rr(2)^(1/3);
end
v=-p/u;
In theory, either rr(1) or rr(2) gives the same set of roots, but the larger one will contain relatively less roundoff error.
27 Oct 2005
Raymond Kan
To fix the problem, change lines 50 and 51 to
u=sign(rr(1))*abs(rr(1))^(1/3);
v=sign(rr(2))*abs(rr(2))^(1/3);
31 Mar 2005
Marcelo Pisani
There is an error for 3rd degree polynomials solving using ROOT1. I just tryied this:
---
a=[3 -2 3 -4];
r=roots(a)
r1=roots1(a)
polyval(a,r)
polyval(a,r1)
---