


@info:
! @deftypefn {Function File} {[@var{D}, @var{err}] =} A_times_B_kronecker_C (@var{A},@var{B},@var{C},@var{fake})
! @anchor{kronecker/A_times_B_kronecker_C}
! @sp 1
! Computes A*kron(B,C).
! @sp 2
! @strong{Inputs}
! @sp 1
! @table @ @var
! @item A
! mA*nA matrix of doubles.
! @item B
! mB*nB matrix of doubles.
! @item C
! mC*nC matrix of doubles.
! @item fake
! Anything you want, just a fake parameter (because the mex version admits a last argument specifying the number of threads to be used in parallel mode).
! @end table
! @sp 2
! @strong{Outputs}
! @sp 1
! @table @ @var
! @item D
! mA*(nC*nB) or mA*(nB*nB) matrix of doubles.
! @item err
! Integer scalar equal to zero (if all goes well).
! @end table
! @sp 2
! @strong{Remarks}
! @sp 1
! [1] This routine is called by Dynare if and only the mex version is not compiled (also used for testing purposes).
! @sp 1
! [2] This routine can be called with three or four arguments. In the first case A*kron(B,B) is computed.
! @sp 2
! @strong{This function is called by:}
! @sp 1
! @ref{kronecker/sparse_hessian_times_B_kronecker_C}, @ref{dr1}, @ref{simult_}
! @sp 2
! @strong{This function calls:}
!
! @end deftypefn
@eod:

0001 function [D, err] = A_times_B_kronecker_C(A,B,C,fake) 0002 0003 %@info: 0004 %! @deftypefn {Function File} {[@var{D}, @var{err}] =} A_times_B_kronecker_C (@var{A},@var{B},@var{C},@var{fake}) 0005 %! @anchor{kronecker/A_times_B_kronecker_C} 0006 %! @sp 1 0007 %! Computes A*kron(B,C). 0008 %! @sp 2 0009 %! @strong{Inputs} 0010 %! @sp 1 0011 %! @table @ @var 0012 %! @item A 0013 %! mA*nA matrix of doubles. 0014 %! @item B 0015 %! mB*nB matrix of doubles. 0016 %! @item C 0017 %! mC*nC matrix of doubles. 0018 %! @item fake 0019 %! Anything you want, just a fake parameter (because the mex version admits a last argument specifying the number of threads to be used in parallel mode). 0020 %! @end table 0021 %! @sp 2 0022 %! @strong{Outputs} 0023 %! @sp 1 0024 %! @table @ @var 0025 %! @item D 0026 %! mA*(nC*nB) or mA*(nB*nB) matrix of doubles. 0027 %! @item err 0028 %! Integer scalar equal to zero (if all goes well). 0029 %! @end table 0030 %! @sp 2 0031 %! @strong{Remarks} 0032 %! @sp 1 0033 %! [1] This routine is called by Dynare if and only the mex version is not compiled (also used for testing purposes). 0034 %! @sp 1 0035 %! [2] This routine can be called with three or four arguments. In the first case A*kron(B,B) is computed. 0036 %! @sp 2 0037 %! @strong{This function is called by:} 0038 %! @sp 1 0039 %! @ref{kronecker/sparse_hessian_times_B_kronecker_C}, @ref{dr1}, @ref{simult_} 0040 %! @sp 2 0041 %! @strong{This function calls:} 0042 %! 0043 %! @end deftypefn 0044 %@eod: 0045 0046 % Copyright (C) 1996-2011 Dynare Team 0047 % stephane DOT adjemian AT univ DASH lemans DOT fr 0048 % 0049 % This file is part of Dynare. 0050 % 0051 % Dynare is free software: you can redistribute it and/or modify 0052 % it under the terms of the GNU General Public License as published by 0053 % the Free Software Foundation, either version 3 of the License, or 0054 % (at your option) any later version. 0055 % 0056 % Dynare is distributed in the hope that it will be useful, 0057 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0058 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0059 % GNU General Public License for more details. 0060 % 0061 % You should have received a copy of the GNU General Public License 0062 % along with Dynare. If not, see <http://www.gnu.org/licenses/>. 0063 0064 % Chek number of inputs and outputs. 0065 if nargin>4 || nargin<3 0066 error('A_times_B_kronecker_C takes 3 or 4 input arguments and provides 2 output arguments.') 0067 end 0068 0069 0070 % Get & check dimensions. Initialization of the output matrix. 0071 [mA,nA] = size(A); 0072 [mB,nB] = size(B); 0073 if nargin == 4 0074 [mC,nC] = size(C); 0075 if mB*mC ~= nA 0076 error('Input dimension error!') 0077 end 0078 D = zeros(mA,nB*nC); 0079 loop = (mB*nB*mC*nC > 1e7); 0080 else 0081 if mB*mB ~= nA 0082 error('Input dimension error!') 0083 end 0084 D = zeros(mA,nB*nB); 0085 loop = (mB*nB*mB*nB > 1e7); 0086 end 0087 % Computational part. 0088 if loop 0089 if nargin == 4 0090 k1 = 1; 0091 for i1=1:nB 0092 for i2=1:nC 0093 D(:,k1) = A * kron(B(:,i1),C(:,i2)); 0094 k1 = k1 + 1; 0095 end 0096 end 0097 else 0098 k1 = 1; 0099 for i1=1:nB 0100 for i2=1:nB 0101 D(:,k1) = A * kron(B(:,i1),B(:,i2)); 0102 k1 = k1 + 1; 0103 end 0104 end 0105 end 0106 else 0107 if nargin == 4 0108 D = A * kron(B,C); 0109 else 0110 D = A * kron(B,B); 0111 end 0112 end 0113 err = 0;