Home > classes > @ao > svd.m

svd

PURPOSE ^

SVD overloads the determinant function for Analysis objects.

SYNOPSIS ^

function varargout = svd(varargin)

DESCRIPTION ^

 SVD overloads the determinant function for Analysis objects.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: SVD overloads the determinant function for Analysis objects.

 CALL:        u        = svd (a,pl)
             [u, s]    = svd (a,pl)
             [u, s, v] = svd (a,pl)
             [u, s, v] = svd (a)

 INPUTS:      a    - input analysis object
              pl   - a parameter list

 OTPUTS:      like matlab fct

 PARAMETERS:  'option' - a string or value that can be submited  i.e. 'econ'
                         to produve economy size decomposition
                       - options are the same as for the matlab function

              The following call returns a parameter list object that
              contains the default parameter values:

              >> pl = svd(ao, 'Params')

 VERSION:     $Id: svd.m,v 1.13 2007/11/26 14:48:13 ingo Exp $

 HISTORY:     08-05-07A Monsky
                Creation.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = svd(varargin)
0002 % SVD overloads the determinant function for Analysis objects.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: SVD overloads the determinant function for Analysis objects.
0007 %
0008 % CALL:        u        = svd (a,pl)
0009 %             [u, s]    = svd (a,pl)
0010 %             [u, s, v] = svd (a,pl)
0011 %             [u, s, v] = svd (a)
0012 %
0013 % INPUTS:      a    - input analysis object
0014 %              pl   - a parameter list
0015 %
0016 % OTPUTS:      like matlab fct
0017 %
0018 % PARAMETERS:  'option' - a string or value that can be submited  i.e. 'econ'
0019 %                         to produve economy size decomposition
0020 %                       - options are the same as for the matlab function
0021 %
0022 %              The following call returns a parameter list object that
0023 %              contains the default parameter values:
0024 %
0025 %              >> pl = svd(ao, 'Params')
0026 %
0027 % VERSION:     $Id: svd.m,v 1.13 2007/11/26 14:48:13 ingo Exp $
0028 %
0029 % HISTORY:     08-05-07A Monsky
0030 %                Creation.
0031 %
0032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0033 
0034 VERSION  = '$Id: svd.m,v 1.13 2007/11/26 14:48:13 ingo Exp $';
0035 
0036 U = [];
0037 S = [];
0038 V = [];
0039 
0040 %% Check if this is a call for parameters
0041 
0042 if nargin == 2
0043   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0044     in = char(varargin{2});
0045     if strcmp(in, 'Params')
0046       varargout{1} = getDefaultPL();
0047       return
0048     elseif strcmp(in, 'Version')
0049       varargout{1} = VERSION;
0050       return
0051     end
0052   end
0053 end
0054 
0055 %% Collect input ao's, plist's and ao variable names
0056 in_names = {};
0057 for ii = 1:nargin
0058   in_names{end+1} = inputname(ii);
0059 end
0060 
0061 [as, pl, invars] = collect_inputs(varargin, in_names);
0062 
0063 if ~isempty (pl)
0064   pl = combine(pl);
0065 end
0066 
0067 % check plist
0068 if ~isempty (pl)
0069   pl = combine(pl);
0070 end
0071 
0072 % Check input analysis object
0073 for j=1:numel(as)
0074   a = as(j);
0075 
0076   d = get(a, 'data');
0077   dinfo = whos('d');
0078 
0079   % Which data type do we have
0080   dtype = dinfo.class;
0081 
0082   udata = [];
0083   sdata = [];
0084   vdata = [];
0085 
0086   switch dtype
0087     case 'cdata'
0088       disp('* DETERMINANT of cdata object');
0089       if nargout <= 1
0090         [h, udata] = single_operation(a.data, 'svd',pl);
0091       elseif nargout == 2
0092         [h, udata, sdata] = single_operation(a.data, 'svd',pl);
0093       elseif nargout == 3
0094         [h, udata, sdata, vdata] = single_operation(a.data, 'svd',pl);
0095       end
0096       %create analysis object(s)
0097       h = set(h, 'inhists', [a.hist]);
0098 
0099       %% Set the var_name to the history
0100       h = set(h, 'invars', cellstr(invars{j}));
0101 
0102       u = ao(udata, h);
0103       u = setnh(u, 'name',  sprintf('u_svd(%s)', char(invars{j})));
0104       U = [U u];
0105       if ~isempty(sdata)
0106         s = ao(sdata, h);
0107         s = setnh(s, 'name',  sprintf('s_svd(%s)', char(invars{j})));
0108         S = [S s];
0109       end
0110       if ~isempty(vdata)
0111         v = ao(vdata, h);
0112         v = setnh(v, 'name',  sprintf('v_svd(%s)', char(invars{j})));
0113         V = [V v];
0114       end
0115 
0116     case {'tsdata','fsdata','xydata'}
0117       error('### this function works for cdata type AO only')
0118     otherwise
0119       error('### unknown data type.')
0120   end
0121 
0122 end
0123 
0124 % Reshape the ouput to the same size of the input
0125 U = reshape(U, size(as));
0126 varargout{1} = U;
0127 
0128 if nargout > 1
0129   % Reshape the ouput to the same size of the input
0130   S = reshape(S, size(as));
0131   varargout{2} = S;
0132   if nargout > 2
0133     % Reshape the ouput to the same size of the input
0134     V = reshape(V, size(as));
0135     varargout{3} = V;
0136     if nargout > 3
0137       error('### wrong number of outputs')
0138     end
0139   end
0140 end
0141 
0142 %% Get default params
0143 function plo = getDefaultPL()
0144 
0145 plo = plist();
0146 plo = append(plo, 'option', []);
0147 
0148 % END

Generated on Tue 22-Jan-2008 10:39:13 by m2html © 2003