1function cprod = cartesian_product_of_sets(varargin) 2% Computes the cartesian product. 3 4%@info: 5%! @deftypefn {Function File} {@var{cprod} =} cartesian_product_of_sets (@var{a},@var{b}, ...) 6%! @anchor{cartesian_product_of_sets} 7%! @sp 1 8%! Computes A_1 * A_2 * .... * A_n with a generic set A_i = {e_1,e_2,e_3,...} where e_i is a string 9%! or a number. It is assumed that each element e_i is unique in set A_i. 10%! @sp 2 11%! @strong{Inputs} 12%! @sp 1 13%! @table @ @var 14%! @item a 15%! n*1 vector of doubles. 16%! @item a 17%! m*1 vector of doubles. 18%! @end table 19%! @sp 1 20%! @strong{Outputs} 21%! @sp 1 22%! @table @ @var 23%! @item cprod 24%! nm*2 matrix of doubles, the nodes cartesian product of sets @var{a} and @var{b}. 25%! @end table 26%! @sp 2 27%! @strong{This function is called by:} 28%! @sp 2 29%! @strong{This function calls:} 30%! @sp 2 31%! @end deftypefn 32%@eod: 33 34% Copyright (C) 2011-2017 Dynare Team 35% 36% This file is part of Dynare. 37% 38% Dynare is free software: you can redistribute it and/or modify 39% it under the terms of the GNU General Public License as published by 40% the Free Software Foundation, either version 3 of the License, or 41% (at your option) any later version. 42% 43% Dynare is distributed in the hope that it will be useful, 44% but WITHOUT ANY WARRANTY; without even the implied warranty of 45% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 46% GNU General Public License for more details. 47% 48% You should have received a copy of the GNU General Public License 49% along with Dynare. If not, see <http://www.gnu.org/licenses/>. 50 51% Original author: stephane DOT adjemian AT univ DASH lemans DOT fr 52 53[ F{1:nargin} ] = ndgrid( varargin{:} ); 54 55for i=1:nargin 56 cprod(:,i) = F{i}(:); 57end