Rev | Line | |
---|
[37] | 1 | function p = poly (A, r) |
---|
| 2 | % POLY (Overloaded) |
---|
| 3 | % |
---|
| 4 | % Computes the coefficients of the characteristic polynomial, det (sI-A), |
---|
| 5 | % of a square matrix, A, using Berkowitz algorithm. |
---|
| 6 | % |
---|
| 7 | % p = poly(A) |
---|
| 8 | % |
---|
| 9 | % Stuart J. Berkowitz, "On computing determinat in small parallel time |
---|
| 10 | % using a small number of processors. Information Processing Letters, |
---|
| 11 | % 18(3):147-150, 1984. |
---|
| 12 | % |
---|
| 13 | % See also DET |
---|
| 14 | |
---|
| 15 | % Author Anders Helmersson, Johan Löfberg |
---|
| 16 | % $Id: poly.m,v 1.2 2006/10/24 12:02:04 joloef Exp $% |
---|
| 17 | |
---|
| 18 | [n, m] = size (A); |
---|
| 19 | if n ~= m, error ('A must be square'); end; |
---|
| 20 | |
---|
| 21 | p = 1; |
---|
| 22 | |
---|
| 23 | for k = n: -1: 1, |
---|
| 24 | M = extsubsref(A,k+1:n,k+1:n); |
---|
| 25 | R = extsubsref(A,k,k+1:n); |
---|
| 26 | S = extsubsref(A,k+1:n,k); |
---|
| 27 | ci = [1 -extsubsref(A,k,k)]; |
---|
| 28 | for i = k+1:n |
---|
| 29 | ci = [ci -R*S]; |
---|
| 30 | if (i < n) R = R*M; end |
---|
| 31 | end |
---|
| 32 | C = toeplitz (ci, [1 zeros(1,n-k)]); |
---|
| 33 | p = C * p; |
---|
| 34 | end |
---|
| 35 | p = p'; |
---|
| 36 | |
---|
| 37 | if nargin >= 2, p = p(n+1-r); end |
---|
Note: See
TracBrowser
for help on using the repository browser.