Code covered by the BSD License  

Highlights from
Sylvester Matrix (v1.0, may 2009)

from Sylvester Matrix (v1.0, may 2009) by Jos (10584)
SYLVESTER - Sylvester matrix of two polynomials

sylvester(P,Q)
function M = sylvester(P,Q)
% SYLVESTER - Sylvester matrix of two polynomials
%   SYLVESTER(P,Q) returns the Sylvester Matrix associated with the two
%   polynomial representations P and Q. M is a N-by-N square matrix with
%   N being the total number of elements of P and Q.
%
%   Example:
%     P = [1 2 3 4] ; Q =  [6 7] ;
%     M = sylvester(P,Q)
%     % ->   1     2     3     4     0
%     %      0     1     2     3     4
%     %      6     7     0     0     0
%     %      0     6     7     0     0
%     %      0     0     6     7     0
%     %      0     0     0     6     7
%
%   For more information, see http://en.wikipedia.org/wiki/Sylvester_matrix
%
%   See also GALLERY, TOEPLITZ
%            CIRCULANT (File Exchange)

% for Matlab R13 and up
% version 1.0 (may 2009)
% (c) Jos van der Geest
% email: jos@jasen.nl

% History
% 1.0 (may 2009) - created, inpsired by a post on CSSM

error(nargchk(2,2,nargin)) ;

NP = numel(P) ;
NQ = numel(Q) ;

if ~isnumeric(P) || ~isnumeric(Q) || NP==0 || NQ==0,
    error('Input arguments should be numeric vectors.') ;
end

% turn off TOEPLITZ warning
WS = warning('off','MATLAB:toeplitz:DiagonalConflict')

% create Sylvester matrix
MP = toeplitz([P(:) ; zeros(NQ-1,1)],zeros(NQ,1)) ;
MQ = toeplitz([Q(:) ; zeros(NP-1,1)],zeros(NP,1)) ;
M = [MP MQ].' ;

warning(WS.state,WS.identifier)

Contact us at files@mathworks.com