comparison scripts/polynomial/poly.m @ 904:3470f1e25a79

[project @ 1994-11-09 21:22:15 by jwe]
author jwe
date Wed, 09 Nov 1994 21:22:15 +0000
parents c5d35bb139b6
children f558749713f1
comparison
equal deleted inserted replaced
903:b3692d63cca3 904:3470f1e25a79
1 function y = poly (x) 1 function y = poly (x)
2 #
3 # If A is a square n-by-n matrix, poly (A) is the row vector of
4 # the coefficients of det (z * eye(n) - A), the characteristic
5 # polynomial of A.
6 # If x is a vector, poly (x) is a vector of coefficients of the
7 # polynomial whose roots are the elements of x.
8 2
9 # Written by KH (Kurt.Hornik@neuro.tuwien.ac.at) on Dec 24, 1993 3 # If A is a square n-by-n matrix, poly (A) is the row vector of
10 # Copyright Dept of Probability Theory and Statistics TU Wien 4 # the coefficients of det (z * eye(n) - A), the characteristic
5 # polynomial of A.
6 # If x is a vector, poly (x) is a vector of coefficients of the
7 # polynomial whose roots are the elements of x.
8
9 # Written by KH (Kurt.Hornik@neuro.tuwien.ac.at) on Dec 24, 1993
10 # Copyright Dept of Probability Theory and Statistics TU Wien
11 11
12 m = min (size (x)); 12 m = min (size (x));
13 n = max (size (x)); 13 n = max (size (x));
14 if (m == 0) 14 if (m == 0)
15 y = 1; 15 y = 1;
16 elseif (m == 1) 16 elseif (m == 1)
17 v = x; 17 v = x;
18 elseif (m == n) 18 elseif (m == n)
19 v = eig (x); 19 v = eig (x);
20 else 20 else
21 error ("usage: poly(x), where x is a vector or a square matrix"); 21 usage ("poly(x), where x is a vector or a square matrix");
22 endif 22 endif
23 23
24 y = [1, zeros (1, n)]; 24 y = [1, zeros (1, n)];
25 for j = 1:n; 25 for j = 1:n;
26 y(2:(j+1)) = y(2:(j+1)) - v(j) .* y(1:j); 26 y(2:(j+1)) = y(2:(j+1)) - v(j) .* y(1:j);