mrandomn.pro

来自「basic median filter simulation」· PRO 代码 · 共 69 行

PRO
69
字号
function mrandomn, seed, covar, nrand;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+;  NAME:;     MRANDOMN; PURPOSE:; Function to draw NRAND random deviates from a multivariate normal; distribution with zero mean and covariance matrix COVAR.; ; AUTHOR : Brandon C. Kelly, Steward Obs., Sept. 2004;; INPUTS : ;;    SEED - The random number generator seed, the default is IDL's;           default in RANDOMN();    COVAR - The covariance matrix of the multivariate normal;            distribution.    ; OPTIONAL INPUTS :;;    NRAND - The number of randomn deviates to draw. The default is;            one.; OUTPUT :;;    The random deviates, an [NRAND, NP] array where NP is the;    dimension of the covariance matrix, i.e., the number of;    parameters.;; ROUTINES CALLED :;;    POSITIVE, DIAG;-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;if n_params() lt 2 then begin    print, 'Syntax- Result = mrandomn( seed, covar, [nrand] )'    return, 0endif;check inputs and set up defaultsif n_elements(nrand) eq 0 then nrand = 1if size(covar, /n_dim) ne 2 then begin    print, 'COVAR must be a matrix.'    return, 0endifnp = (size(covar))[1]if (size(covar))[2] ne np then begin    print, 'COVAR must be a square matrix.'    return, 0endifdiag = lindgen(np) * (np + 1L)epsilon = randomn(seed, nrand, np) ;standard normal random deviates (NP x NRAND matrix)A = covar  ;store covariance into dummy variable for input into TRIREDcholdc, A, P, /double           ;do Cholesky decompositionfor j = 0, np - 1 do for i = j, np - 1 do A[i,j] = 0dA[diag] = P;transform standard normal deviates so they have covariance matrix COVARepsilon = A ## epsilonreturn, epsilonend

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?