Home > Community > Forums > Custom IC SKILL > how to create an arbitrary size matrix with the elements alonging with specific distribution?

## Email

Recipients email * (separate multiple addresses with commas)

Message *

 Send yourself a copy

## Subscribe

Intro copy of the newsletter section here, some intro copy of the newsletter. Instruction of how to subscribe to this newsletter.

First Name *

Last Name *

Email *

Company / Institution *

 Send Yourself A Copy

# how to create an arbitrary size matrix with the elements alonging with specific distribution?

Last post Fri, Nov 30 2012 6:32 AM by Andrew Beckett. 1 replies.
 Started by imagesensor123 30 Nov 2012 02:00 AM. Topic has 1 replies and 517 views
• #### Fri, Nov 30 2012 2:00 AM

how to create an arbitrary size matrix with the elements alonging with specific distribution?
 Hello,       I would like to create a matrix size, such as 100x100, all these 10000 elements in the matrix is in normal distribution. how can I set up the matrix? how can I arrange these elements in random position in the matrix.      for example: I have 10 elements equal to "20"                                   5 elements equal to "100"                                   ...      I'd like these ten elements "20" to be set randomly in the matrix 100x100.welcome to any discussion regards,zfeng Regards, zfeng
• Post Points: 20
• #### Fri, Nov 30 2012 6:32 AM

Re: how to create an arbitrary size matrix with the elements alonging with specific distribution?
 Zfeng,Something like this:procedure(CCFbuildMatrix(N mean sigma)  let((matrix column)    matrix=makeVector(N)    for(x 0 N-1      matrix[x]=column=makeVector(N)      for(y 0 N-1        ; convert to integer, clip, do whatever you want here.        ; in this case I just stretched the normal distribution to the        ; desired mean and standard deviation        column[y]=abRandomNormal()*sigma+mean      )    )  matrix  ))This uses the code below to generate random numbers with a gaussian distribution. The return value of this is a matrix - so you can do:> m=CCFbuildMatrix(100 50 10)array@0x90ac678> m[2][4]53.99555> m[6][8]47.73704For example. ```/* abRandomNormal.il Author A.D.Beckett Group Custom IC (UK), Cadence Design Systems Ltd. Language SKILL Date Modified By Uses Box-Muller method to produce random numbers with a normal distribution (mean 0, std dev 1). Call abRandomNormal() multiple times to get such a sequence. *************************************************** SCCS Info: @(#) abRandomNormal.il 11/30/12.14:22:28 1.1 */ ;------------------------------------------------------------------------ ; Store math constants (such as PI) as properties on this symbol ;------------------------------------------------------------------------ (defMathConstants 'abRandomNormal) /*************************************************************** * * * (abRandomNormal) * * * * Return a random number with normal distribution using the * * Box-Muller method * * * ***************************************************************/ (defun abRandomNormal () (let ((max (rightshift -1 1)) U V) (setq U (quotient (float (random max)) max)) (setq V (quotient (float (random max)) max)) ;-------------------------------------------------------------------- ; could generate two independent numbers ; the other would use cos instead of sin ;-------------------------------------------------------------------- (times (sqrt (times -2 (log U))) (cos (times 2 (getqq abRandomNormal PI) V))) ) ) /*************************************************************** * * * (abTestRandomNormal numPoints bins) * * * * Function for testing - uses ViVA's plotting functions to * * produce a histogram and also compute the mean and std dev * * to ensure that with enough points it looks normal * * (e.g numPoints 100000, bins 100) * * * ***************************************************************/ (defun abTestRandomNormal (numPoints bins) (let (x y wave) (setq x (drCreateVec 'intlong numPoints)) (setq y (drCreateVec 'double numPoints)) (for i 0 numPoints (drAddElem x i) (drAddElem y (abRandomNormal)) ) (setq wave (drCreateWaveform x y)) (awvPlotWaveform (newWindow) (list (histo wave bins nil nil))) (printf "Mean=%g\nStd Dev=%g\n" (average wave) (stddev wave)) ) ) ```Regards, Andrew.
• Post Points: 5