Home > matlab > cartesian_product_of_sets.m

cartesian_product_of_sets

PURPOSE ^

Computes the cartesian product.

SYNOPSIS ^

function cprod = cartesian_product_of_sets(varargin)

DESCRIPTION ^

 Computes the cartesian product.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function cprod = cartesian_product_of_sets(varargin)
0002 % Computes the cartesian product.
0003 
0004 %@info:
0005 %! @deftypefn {Function File} {@var{cprod} =} cartesian_product_of_sets (@var{a},@var{b}, ...)
0006 %! @anchor{cartesian_product_of_sets}
0007 %! @sp 1
0008 %! 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
0009 %! or a number. It is assumed that each element e_i is unique in set A_i.
0010 %! @sp 2
0011 %! @strong{Inputs}
0012 %! @sp 1
0013 %! @table @ @var
0014 %! @item a
0015 %! n*1 vector of doubles.
0016 %! @item a
0017 %! m*1 vector of doubles.
0018 %! @end table
0019 %! @sp 1
0020 %! @strong{Outputs}
0021 %! @sp 1
0022 %! @table @ @var
0023 %! @item cprod
0024 %! nm*2 matrix of doubles, the nodes cartesian product of sets @var{a} and @var{b}.
0025 %! @end table
0026 %! @sp 2
0027 %! @strong{This function is called by:}
0028 %! @sp 2
0029 %! @strong{This function calls:}
0030 %! @sp 2
0031 %! @end deftypefn
0032 %@eod:
0033 
0034 % Copyright (C) 2011 Dynare Team
0035 % stephane DOT adjemian AT univ DASH lemans DOT fr
0036 %
0037 % This file is part of Dynare.
0038 %
0039 % Dynare is free software: you can redistribute it and/or modify
0040 % it under the terms of the GNU General Public License as published by
0041 % the Free Software Foundation, either version 3 of the License, or
0042 % (at your option) any later version.
0043 %
0044 % Dynare is distributed in the hope that it will be useful,
0045 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0046 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0047 % GNU General Public License for more details.
0048 %
0049 % You should have received a copy of the GNU General Public License
0050 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0051 
0052 [ F{1:nargin} ] = ndgrid( varargin{:} );
0053 
0054 for i=1:nargin
0055     cprod(:,i) = F{i}(:);
0056 end

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005