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')

 The following call returns a string that contains the routine CVS version:

 >> version = svd(ao,'Version')

 The following call returns a string that contains the routine category:

 >> category = svd(ao,'Category')

 VERSION:     $Id: svd.html,v 1.14 2008/03/31 10:27:33 hewitson 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 contains the
0023 % default parameter values:
0024 %
0025 % >> pl = svd(ao,'Params')
0026 %
0027 % The following call returns a string that contains the routine CVS version:
0028 %
0029 % >> version = svd(ao,'Version')
0030 %
0031 % The following call returns a string that contains the routine category:
0032 %
0033 % >> category = svd(ao,'Category')
0034 %
0035 % VERSION:     $Id: svd.html,v 1.14 2008/03/31 10:27:33 hewitson Exp $
0036 %
0037 % HISTORY:     08-05-07A Monsky
0038 %                Creation.
0039 %
0040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0041 
0042 VERSION  = '$Id: svd.html,v 1.14 2008/03/31 10:27:33 hewitson Exp $';
0043 CATEGORY = 'Operator';
0044 
0045 U = [];
0046 S = [];
0047 V = [];
0048 
0049 %% Check if this is a call for parameters
0050 
0051 if nargin == 2
0052   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0053     in = char(varargin{2});
0054     if strcmp(in, 'Params')
0055       varargout{1} = getDefaultPL();
0056       return
0057     elseif strcmp(in, 'Version')
0058       varargout{1} = VERSION;
0059       return
0060     elseif strcmp(in, 'Category')
0061       varargout{1} = CATEGORY;
0062       return
0063     end
0064   end
0065 end
0066 
0067 %% Collect input ao's, plist's and ao variable names
0068 in_names = {};
0069 for ii = 1:nargin
0070   in_names{end+1} = inputname(ii);
0071 end
0072 
0073 [as, pl, invars] = collect_inputs(varargin, in_names);
0074 
0075 if ~isempty (pl)
0076   pl = combine(pl);
0077 end
0078 
0079 % check plist
0080 if ~isempty (pl)
0081   pl = combine(pl);
0082 end
0083 
0084 % Check input analysis object
0085 for j=1:numel(as)
0086   a = as(j);
0087 
0088   d = get(a, 'data');
0089   dinfo = whos('d');
0090 
0091   % Which data type do we have
0092   dtype = dinfo.class;
0093 
0094   udata = [];
0095   sdata = [];
0096   vdata = [];
0097 
0098   switch dtype
0099     case 'cdata'
0100       if nargout <= 1
0101         [h, udata] = single_operation(a.data, 'svd',pl);
0102       elseif nargout == 2
0103         [h, udata, sdata] = single_operation(a.data, 'svd',pl);
0104       elseif nargout == 3
0105         [h, udata, sdata, vdata] = single_operation(a.data, 'svd',pl);
0106       end
0107       %create analysis object(s)
0108       h = set(h, 'inhists', [a.hist]);
0109 
0110       %% Set the var_name to the history
0111       h = set(h, 'invars', cellstr(invars{j}));
0112 
0113       u = ao(udata, h);
0114       u = setnh(u, 'name',  sprintf('u_svd(%s)', char(invars{j})));
0115       U = [U u];
0116       if ~isempty(sdata)
0117         s = ao(sdata, h);
0118         s = setnh(s, 'name',  sprintf('s_svd(%s)', char(invars{j})));
0119         S = [S s];
0120       end
0121       if ~isempty(vdata)
0122         v = ao(vdata, h);
0123         v = setnh(v, 'name',  sprintf('v_svd(%s)', char(invars{j})));
0124         V = [V v];
0125       end
0126 
0127     case {'tsdata','fsdata','xydata'}
0128       error('### this function works for cdata type AO only')
0129     otherwise
0130       error('### unknown data type.')
0131   end
0132 
0133 end
0134 
0135 % Reshape the ouput to the same size of the input
0136 U = reshape(U, size(as));
0137 varargout{1} = U;
0138 
0139 if nargout > 1
0140   % Reshape the ouput to the same size of the input
0141   S = reshape(S, size(as));
0142   varargout{2} = S;
0143   if nargout > 2
0144     % Reshape the ouput to the same size of the input
0145     V = reshape(V, size(as));
0146     varargout{3} = V;
0147     if nargout > 3
0148       error('### wrong number of outputs')
0149     end
0150   end
0151 end
0152 
0153 %% Get default params
0154 function plo = getDefaultPL()
0155 
0156 plo = plist();
0157 plo = append(plo, 'option', []);
0158 
0159 % END

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003