2010-09-21 10:40:18 +02:00
|
|
|
function [err, D] = A_times_B_kronecker_C(A,B,C)
|
|
|
|
%function [err, D] = A_times_B_kronecker_C(A,B,C)
|
2008-04-25 14:47:30 +02:00
|
|
|
% Computes A * kron(B,C).
|
|
|
|
%
|
|
|
|
% INPUTS
|
2010-09-21 10:40:18 +02:00
|
|
|
% A [double] mA*nA matrix.
|
|
|
|
% B [double] mB*nB matrix.
|
|
|
|
% C [double] mC*nC matrix.
|
|
|
|
%
|
2008-04-25 14:47:30 +02:00
|
|
|
% OUTPUTS
|
2010-09-21 10:40:18 +02:00
|
|
|
% err [double] scalar: 1 indicates failure, 0 indicates success
|
|
|
|
% D [double] mA*(nC*nB) or mA*(nB*nB) matrix.
|
|
|
|
%
|
2008-04-25 14:47:30 +02:00
|
|
|
% ALGORITHM
|
|
|
|
% none.
|
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none.
|
2008-08-01 14:40:33 +02:00
|
|
|
|
2010-09-22 11:40:13 +02:00
|
|
|
% Copyright (C) 1996-2010 Dynare Team
|
2008-08-01 14:40:33 +02:00
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare 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.
|
|
|
|
%
|
|
|
|
% Dynare 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 Dynare. If not, see <http://www.gnu.org/licenses/>.
|
2009-12-16 18:17:34 +01:00
|
|
|
|
2008-04-25 14:47:30 +02:00
|
|
|
% Chek number of inputs and outputs.
|
2010-09-21 10:40:18 +02:00
|
|
|
if nargin>3 || nargin<2 || nargout~=2
|
|
|
|
error('A_times_B_kronecker_C takes 2 or 3 input arguments and provides exactly 2 output arguments.')
|
2008-04-25 14:47:30 +02:00
|
|
|
end
|
|
|
|
% Get & check dimensions. Initialization of the output matrix.
|
|
|
|
[mA,nA] = size(A);
|
|
|
|
[mB,nB] = size(B);
|
|
|
|
if nargin == 3
|
|
|
|
[mC,nC] = size(C);
|
2008-05-16 10:18:37 +02:00
|
|
|
if mB*mC ~= nA
|
2008-04-25 14:47:30 +02:00
|
|
|
error('Input dimension error!')
|
|
|
|
end
|
|
|
|
D = zeros(mA,nB*nC);
|
|
|
|
loop = (mB*nB*mC*nC > 1e7);
|
|
|
|
else
|
|
|
|
if mB*mB ~= nA
|
|
|
|
error('Input dimension error!')
|
|
|
|
end
|
2008-05-16 10:18:37 +02:00
|
|
|
D = zeros(mA,nB*nB);
|
2008-04-25 14:47:30 +02:00
|
|
|
loop = (mB*nB*mB*nB > 1e7);
|
|
|
|
end
|
|
|
|
% Computational part.
|
|
|
|
if loop
|
|
|
|
if nargin == 3
|
|
|
|
k1 = 1;
|
|
|
|
for i1=1:nB
|
|
|
|
for i2=1:nC
|
|
|
|
D(:,k1) = A * kron(B(:,i1),C(:,i2));
|
|
|
|
k1 = k1 + 1;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
k1 = 1;
|
|
|
|
for i1=1:nB
|
|
|
|
for i2=1:nB
|
|
|
|
D(:,k1) = A * kron(B(:,i1),B(:,i2));
|
|
|
|
k1 = k1 + 1;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if nargin == 3
|
|
|
|
D = A * kron(B,C);
|
|
|
|
else
|
|
|
|
D = A * kron(B,B);
|
|
|
|
end
|
2010-09-21 10:40:18 +02:00
|
|
|
end
|
|
|
|
err = 0;
|