-
Notifications
You must be signed in to change notification settings - Fork 5
/
ckron.m
35 lines (29 loc) · 831 Bytes
/
ckron.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
% CKRON Repeated Kronecker products on a cell array of matrices.
% USAGE
% z=ckron(b) Solves (B1xB2x...xBd)
% z=ckron(b,1) Solves (inv(B1)xinv(B2)x...xinv(Bd))
% where x denotes Kronecker (tensor) product.
% The Bi are passed as a cell array B.
% Copyright (c) 1997-2000, Paul L. Fackler & Mario J. Miranda
% paul_fackler@ncsu.edu, miranda.4@osu.edu
function z=ckron(b,invert)
if nargin<1, error('At least one parameter must be passed'), end
if nargin==1, invert=0; end
[d,m,n]=csize(b);
if invert && any(m~=n)
error('Matrix elements must be square to invert');
end
if isempty(d)
if invert, z=inv(b); else z=b; end
else
if invert, z=inv(b{1});
else z=b{1};
end
for i=2:d
if invert
z=kronmex(z,inv(b{i}));
else
z=kronmex(z,b{i});
end
end
end