## Copyright (C) 2012 Fotios Kasolis ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## . ## -*- texinfo -*- ## @deftypefn {Function File} address@hidden =} polyeig (@var{C0}, @var{C1}, @dots{}, @var{Cl}) ## @deftypefnx {Function File} {[ @var{v}, @var{z} ] =} polyeig (@var{C0}, @var{C1}, @dots{}, @var{Cl}) ## Solve the polynomial eigenvalue problem of degree @var{l}. ## ## Given a polynomial matrix @var{C0 + C1 s + @dots{} + Cl s^l} polyeig ## solves the generalized eigenvalue problem C v = z D v with C the ## first companion matrix and D = [I, 0; 0, @var{Cl}]. Note that the ## eigenvalues are the roots of the matrix polynomial. ## @end deftypefn ## Author: Fotios Kasolis function [ z, varargout ] = polyeig (varargin) if ( nargout > 2 ) print_usage (); endif inn = numel (varargin); if ! ( issquare (varargin{1}) ) error ("polyeig: coefficients must be square matrices"); endif nin = numel (varargin); n = size (varargin{1}, 1); for cnt = 2 : nin T = varargin{cnt}; nr = size (T, 1); if ! ( issquare (T) && isequal(n, nr) ) error ("polyeig: coefficients must be square matrices with the same dimensions"); endif endfor # matrix polynomial degree l = inn - 1; # form needed matrices C = [ zeros(n * (l - 1), n), eye(n * (l - 1)); -cell2mat(varargin(1 : end - 1)) ]; D = [ eye(n * (l - 1)), zeros(n * (l - 1), n); zeros(n, n * (l - 1)), varargin{end} ]; % solve generalized eigenvalue problem C v = z D v if ( isequal (nargout, 1) ) z = eig (C, D); else [ z, v ] = eig (C, D); varargout{1} = diag (v); endif endfunction # TO DO! # When condeig is implemented allow third output # argument with condition number with respect to # each eigenvalue.