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

Generated on Fri 02-Nov-2007 19:39:27 by m2html © 2003