• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. how to create an arbitrary size matrix with the elements...

Stats

  • Locked Locked
  • Replies 1
  • Subscribers 143
  • Views 13862
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

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

imagesensor123
imagesensor123 over 12 years ago

 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

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 12 years ago

    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.73704

    For 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.

     

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information