function out=nodet(A) % % NODET(A) calculates the characteristic polynomial of a % given square matrix by extracting the linear dependency % relations between iterates of a random vector v. % If A is a scalar, then a random matrix size AxA will be used. % % Compare by calling poly(A) with the same matrix. % % Not yet tested for repeated or nonreal eigenvalues..... % % Matthias Kawski. http://math.la.asu.edu/~kawski % July 2001. All rights reserved. if nargin < 1 A = rand(5,5); end if size(A)==[1,1] A = rand(A); end n = size(A,1); v(:,1)=rand(n,1); % for k = [1:n] v(:,k+1) = A*v(:,k); end v disp('Matrix whose columns are iterates of random vector v') disp('Strike any key top continue') pause % % The (n=1)-st column MUST be linearly dependent on the prior ones. % nn = null(v,'r'); % % fixed multiples of the coefficients of the characteristic % polynomial of A (MATLAB might not have scaled the vector % to have last component equal to one... just to be sure: % poly(A) disp('The characteristic polynomial obtained from poly(A)') disp('Strike any key top continue') pause n0 = nn(n+1); out = flipud(nn/n0)'; disp('The char. poly. as extracted from dependency relations')