Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Solving AM = MB
Date: Wed, 15 Oct 2008 05:19:02 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 32
Message-ID: <gd3ug5$4m6$1@fred.mathworks.com>
References: <gd34pk$csc$1@fred.mathworks.com> <gd36qn$sl9$1@fred.mathworks.com> <gd38sd$eb9$1@fred.mathworks.com> <gd3i4i$13v$1@fred.mathworks.com> <gd3jla$d35$1@fred.mathworks.com> <gd3rtm$c01$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1224047942 4806 172.30.248.38 (15 Oct 2008 05:19:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 15 Oct 2008 05:19:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:495239


kron is neat. Here is another way:

% Data
A=eye(3); A(3)=1;
B=eye(3); B(3)=1;

n=length(A);

% Engine
c(1:n)={A};
BIGA = blkdiag(c{:});

c(1:n)={B.'};
BIGB = blkdiag(c{:});
k=reshape(1:n*n,n,n)';
BIGB=BIGB(k(:),k(:));

M = null(BIGA-BIGB);
% All combination of M(n,n,:) is solution
k=size(M,2);
M = reshape(M,[n n k])

% Test
% random combination
v=rand(1,1,k);
Mrand=bsxfun(@times,M,v);
Mrand=sum(Mrand,3)
% Check
A*Mrand
Mrand*B

% Bruno