Home > pubtools > LatticeTuningFunctions > errors > random > seterrorrand.m

seterrorrand

PURPOSE ^

SYNOPSIS ^

function rrand=seterrorrand(r,... % nominal lattice

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function rrand=seterrorrand(...
0002     r,...             % nominal lattice
0003     positions,...      % positions where to apply the error
0004     errorsetfunct,... % function handle to set the error
0005     seed,...       % seed [m]
0006     sigma,...      % sigma [m]
0007     nsigma,...     % truncation [m]
0008     exixstingerrval)
0009 %
0010 %  rwave=seterrorrand(...
0011 %     r,...             % nominal lattice
0012 %     position,...      % positions where to apply the error
0013 %     errorsetfunct,... % function handle to set the error
0014 %     seed,...       % seed [m]
0015 %     sigma,...      % sigma [m]
0016 %     nsigma)        % truncation [m]% >0 or set to 2
0017 %
0018 % sets error random. errors are defined and applid by the function
0019 % errorsetfunct with signature r=errorsetfunct(r,positions,erroval)
0020 %
0021 % if seed==0 the random stream is not updated.
0022 %
0023 %
0024 %see also: TruncatedGaussian
0025 
0026 if sigma==0
0027     sigma=1e-15;
0028 end
0029 
0030 if nsigma<0
0031     nsigma=2;
0032 end
0033 
0034 if seed~=0
0035     disp(['Setting Random Stream to seed: ' num2str(seed)]);
0036     % set seed
0037     s = RandStream('mcg16807','Seed',seed);
0038     RandStream.setGlobalStream(s);
0039 else
0040    % disp('Using previously set random stream')
0041 end
0042 
0043 % define vector of errors
0044 errorvalues=TruncatedGaussian(...
0045     sigma,...
0046     nsigma*sigma, ...
0047     size(positions));
0048 
0049 if ~isrow(errorvalues)
0050 errorvalues=errorvalues';
0051 end
0052 
0053 % default existing error values
0054 if nargin<7
0055     exixstingerrval=zeros(size(errorvalues));
0056 end
0057 
0058 if ~isrow(exixstingerrval)
0059 exixstingerrval=exixstingerrval';
0060 end
0061 
0062 % apply error
0063 rrand=errorsetfunct(r,positions,exixstingerrval+errorvalues);
0064 
0065 return
0066 
0067

Generated on Thu 24-Aug-2017 18:47:33 by m2html © 2005