1function [D, err] = A_times_B_kronecker_C(A,B,C) 2 3%@info: 4%! @deftypefn {Function File} {[@var{D}, @var{err}] =} A_times_B_kronecker_C (@var{A},@var{B},@var{C}) 5%! @anchor{kronecker/A_times_B_kronecker_C} 6%! @sp 1 7%! Computes A*kron(B,C). 8%! @sp 2 9%! @strong{Inputs} 10%! @sp 1 11%! @table @ @var 12%! @item A 13%! mA*nA matrix of doubles. 14%! @item B 15%! mB*nB matrix of doubles. 16%! @item C 17%! mC*nC matrix of doubles. 18%! @end table 19%! @sp 2 20%! @strong{Outputs} 21%! @sp 1 22%! @table @ @var 23%! @item D 24%! mA*(nC*nB) or mA*(nB*nB) matrix of doubles. 25%! @item err 26%! Integer scalar equal to zero (if all goes well). 27%! @end table 28%! @sp 2 29%! @strong{Remarks} 30%! @sp 1 31%! [1] This routine is called by Dynare if and only the mex version is not compiled (also used for testing purposes). 32%! @sp 1 33%! [2] This routine can be called with three or four arguments. In the first case A*kron(B,B) is computed. 34%! @sp 2 35%! @strong{This function is called by:} 36%! @sp 1 37%! @ref{kronecker/sparse_hessian_times_B_kronecker_C}, @ref{dr1}, @ref{simult_} 38%! @sp 2 39%! @strong{This function calls:} 40%! 41%! @end deftypefn 42%@eod: 43 44% Copyright (C) 1996-2012 Dynare Team 45% 46% This file is part of Dynare. 47% 48% Dynare is free software: you can redistribute it and/or modify 49% it under the terms of the GNU General Public License as published by 50% the Free Software Foundation, either version 3 of the License, or 51% (at your option) any later version. 52% 53% Dynare is distributed in the hope that it will be useful, 54% but WITHOUT ANY WARRANTY; without even the implied warranty of 55% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 56% GNU General Public License for more details. 57% 58% You should have received a copy of the GNU General Public License 59% along with Dynare. If not, see <http://www.gnu.org/licenses/>. 60 61% Original author: stephane DOT adjemian AT univ DASH lemans DOT fr 62 63% Chek number of inputs and outputs. 64if nargin>4 || nargin<3 65 error('A_times_B_kronecker_C takes 3 or 4 input arguments and provides 2 output arguments.') 66end 67 68 69% Get & check dimensions. Initialization of the output matrix. 70[mA,nA] = size(A); 71[mB,nB] = size(B); 72if nargin == 4 73 [mC,nC] = size(C); 74 if mB*mC ~= nA 75 error('Input dimension error!') 76 end 77 D = zeros(mA,nB*nC); 78 loop = (mB*nB*mC*nC > 1e7); 79else 80 if mB*mB ~= nA 81 error('Input dimension error!') 82 end 83 D = zeros(mA,nB*nB); 84 loop = (mB*nB*mB*nB > 1e7); 85end 86% Computational part. 87if loop 88 if nargin == 4 89 k1 = 1; 90 for i1=1:nB 91 for i2=1:nC 92 D(:,k1) = A * kron(B(:,i1),C(:,i2)); 93 k1 = k1 + 1; 94 end 95 end 96 else 97 k1 = 1; 98 for i1=1:nB 99 for i2=1:nB 100 D(:,k1) = A * kron(B(:,i1),B(:,i2)); 101 k1 = k1 + 1; 102 end 103 end 104 end 105else 106 if nargin == 4 107 D = A * kron(B,C); 108 else 109 D = A * kron(B,B); 110 end 111end 112err = 0; 113