Home > m > timetools > statespacefunctions > utp_ltpda_ss_random_generate.m

utp_ltpda_ss_random_generate

PURPOSE ^

utp_ltpda_ss_random_generate subfunction generates a random system

SYNOPSIS ^

function varargout = utp_ltpda_ss_random_generate(varargin)

DESCRIPTION ^

 utp_ltpda_ss_random_generate subfunction generates a random system
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: utp_ltpda_ss_random_generate subfunction generates randomly
 a p-th system out of nSysTot systems, with nUTot exogenous inputs,
 nSysTot possible 'inner' inputs, OutputSizes and InputSizes neing the
 respective sizes of the output sizes of the pSys systems and sizes of the
 nUTot input streams.

 CALL: utp_ltpda_ss_random_generate

 INPUTS: none

 OUTPUTS: 1/0

 ***** THERE ARE NO DEFAULT PARAMETERS *****

 VERSION: '$Id: utp_ltpda_ss_random_generate.html,v 1.4 2008/03/31 10:27:35 hewitson Exp $'

 HISTORY: 22-01-2008 A Grynagier

 TO DO : Nothing
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = utp_ltpda_ss_random_generate(varargin)
0002 % utp_ltpda_ss_random_generate subfunction generates a random system
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 % DESCRIPTION: utp_ltpda_ss_random_generate subfunction generates randomly
0006 % a p-th system out of nSysTot systems, with nUTot exogenous inputs,
0007 % nSysTot possible 'inner' inputs, OutputSizes and InputSizes neing the
0008 % respective sizes of the output sizes of the pSys systems and sizes of the
0009 % nUTot input streams.
0010 %
0011 % CALL: utp_ltpda_ss_random_generate
0012 %
0013 % INPUTS: none
0014 %
0015 % OUTPUTS: 1/0
0016 %
0017 % ***** THERE ARE NO DEFAULT PARAMETERS *****
0018 %
0019 % VERSION: '$Id: utp_ltpda_ss_random_generate.html,v 1.4 2008/03/31 10:27:35 hewitson Exp $'
0020 %
0021 % HISTORY: 22-01-2008 A Grynagier
0022 %
0023 % TO DO : Nothing
0024 %
0025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0026 ALGONAME = mfilename;
0027 VERSION =  '$Id: utp_ltpda_ss_random_generate.html,v 1.4 2008/03/31 10:27:35 hewitson Exp $';
0028 CATEGORY = 'STATESPACE';
0029 display(['starting ' ALGONAME]);
0030 
0031 if isempty(varargin)
0032     nSysTot = 10;
0033     pSys = 1;
0034     nUTot = 10;
0035     OutputSizes = [2 0 0 1 1 2 2 3 3 4 ];
0036     InputSizes = [1 1 1 1 1 2 2 2 2 2 ];
0037 
0038 else
0039     if not(isempty(varargin))
0040         if isequal( varargin{1}, 'Version')
0041             varargout = VERSION;
0042             return;
0043         elseif isequal(varargin{1}, 'Params')
0044             varargout = plist();
0045             return;
0046         elseif isequal(varargin{1}, 'Category')
0047             varargout = CATEGORY;
0048             return;
0049         end
0050     end
0051 
0052     nSysTot = varargin{1};
0053     pSys = varargin{2};
0054     nUTot = varargin{3};
0055     OutputSizes = varargin{4};
0056     InputSizes = varargin{5};
0057 end
0058 
0059 TYPE = 'SUBSYSTEM';
0060 NAME = ['System_', num2str(pSys)];
0061 INPUTNAMES = {};
0062 NBINPUTS_exo = floor((nUTot+1)*rand);
0063 NBINPUTS_in = floor((nSysTot+1)*rand);
0064 NBINPUTS = NBINPUTS_exo + NBINPUTS_in ;
0065 InputsexoVals = ones(NBINPUTS_exo,1) + floor(nUTot*rand(NBINPUTS_exo,1));
0066 InputsInVals = ones(NBINPUTS_in,1) + floor(nSysTot*rand(NBINPUTS_in,1));
0067 for i=1:NBINPUTS_exo
0068     INPUTNAMES = [INPUTNAMES ['U_',num2str(InputsexoVals(i))]];
0069 end
0070 for i=1:NBINPUTS_in
0071     INPUTNAMES = [INPUTNAMES ['Y_',num2str(InputsInVals(i))]];
0072 end
0073 INPUTISUSED = floor(2*rand(NBINPUTS,1));
0074 %time representation for the matrices, given by the timestep for discrete
0075 %case and by a 0 for a time continuous representation
0076 TIMESTEP = 0;  %to be randomized !!!
0077 %declaration of the symbollic variables TO CHANGE AND LOAD DATA FROM A
0078 %PLIST (WRITE FUNCTION TO *MODIFY* THE PLIST SEPARATELY)
0079 NBPARAMS = floor(10*rand);
0080 PARAMNAMES = cell(NBPARAMS,1);
0081 PARAMVALUES = randn(NBPARAMS,1);
0082 PARAMSIGMAS = rand(NBPARAMS,1);
0083 for i=1:NBPARAMS
0084     PARAMNAMES{i} = ['Param_Y', num2str(pSys),'_',num2str(i)];
0085 end
0086 %declaring the symbolic variables
0087 for indice=1:length(PARAMNAMES)
0088     declaration = [  eval(['PARAMNAMES{', num2str(indice),  '}']) , '=sym( ''', eval(['PARAMNAMES{' , num2str(indice), '}']) , ''');'];
0089     eval(declaration);
0090 end
0091 %Making sure no reserved parameter is used
0092 for i=1:length(PARAMNAMES)
0093     if ( (isequal(PARAMNAMES{i},'z')==1) || (isequal(PARAMNAMES{i},'t')==1) || (isequal(PARAMNAMES{i},'T')==1) || (isequal(PARAMNAMES{i},'s')==1) )
0094         msg = ['wrong (reserved for time/frequency) name for variable "',  PARAMNAMES{i}, '" in MatModel from file : ', NAME];
0095         error(msg)
0096     end
0097 end
0098 %Size of state space
0099 nss = floor(abs(2*randn(1)));
0100 A = randn(nss,nss);
0101 C = rand(OutputSizes(pSys),nss);
0102 AMAT = {A};
0103 CMAT = {C};
0104 BMATS = cell(NBINPUTS,1);
0105 DMATS = cell(NBINPUTS,1);
0106 for i=1:NBINPUTS_exo
0107     BMATS{i} = rand(nss,InputSizes(InputsexoVals(i)));
0108     DMATS{i} = rand(OutputSizes(pSys),InputSizes(InputsexoVals(i)));
0109 end
0110 for i=1:NBINPUTS_in
0111     BMATS{i+NBINPUTS_exo} = rand(nss,OutputSizes(InputsInVals(i)));
0112     DMATS{i+NBINPUTS_exo} = rand(OutputSizes(pSys),OutputSizes(InputsInVals(i)));
0113 end
0114 INPUTSIZES = zeros(length(BMATS),1);
0115 for i=1:length(BMATS)
0116     INPUTSIZES(i)= size(BMATS{i},2);
0117 end
0118 XISOUTPUT=floor(2*rand);
0119 YISOUTPUT=floor(2*rand);
0120 XINI = rand(nss,1);
0121 
0122 syst = plist('TYPE', TYPE ,'NAME', NAME ,'TIMESTEP', TIMESTEP , ...
0123     'XISOUTPUT',XISOUTPUT,'YISOUTPUT',YISOUTPUT,'XINI', XINI , ...
0124     'PARAMNAMES', PARAMNAMES ,'PARAMVALUES', PARAMVALUES ,'PARAMSIGMAS', PARAMSIGMAS ,...
0125     'NBINPUTS', NBINPUTS ,'INPUTNAMES', INPUTNAMES ,'INPUTSIZES', INPUTSIZES , 'INPUTISUSED', INPUTISUSED ,...
0126     'AMAT', AMAT ,'BMATS', BMATS ,'CMAT', CMAT ,'DMATS', DMATS );
0127 %making content tests on the subsystem
0128 ltpda_ss_check(syst);
0129 %erasing useless fields
0130 clear A B C D E F PARAMNAMES PARAMVALUES PARAMSIGMAS
0131 %Saving the workspace in the file named "subsystem_GENERATE_workspaceGenerated".
0132 % filename = [mfilename,'_workspaceGenerated'];
0133 % save(filename);
0134 varargout = {syst};
0135 end

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