Create matrix with random numbers

Discussion in 'Ruby' started by Jason Bornhoft, Oct 19, 2007.

  1. I would like to start evaluating Ruby's capabilities in processing large
    linear systems and matrices and I would like to know if there is a
    simple way to 'randomly' populate various matrices regardless of size or
    type.

    Any help, comments, anything is greatly appreciated!
    --
    Posted via http://www.ruby-forum.com/.
     
    Jason Bornhoft, Oct 19, 2007
    #1
    1. Advertising

  2. Jason Bornhoft

    Todd Benson Guest

    On 10/19/07, Jason Bornhoft <> wrote:
    > I would like to start evaluating Ruby's capabilities in processing large
    > linear systems and matrices and I would like to know if there is a
    > simple way to 'randomly' populate various matrices regardless of size or
    > type.
    >
    > Any help, comments, anything is greatly appreciated!


    Not sure what you want exactly, but, maybe...

    require 'matrix'
    a, b = 2, 3
    m = Matrix[*(Array.new(a) {Array.new(b) {rand}})]

    Todd
     
    Todd Benson, Oct 19, 2007
    #2
    1. Advertising

  3. > Not sure what you want exactly, but, maybe...
    >
    > require 'matrix'
    > a, b = 2, 3
    > m = Matrix[*(Array.new(a) {Array.new(b) {rand}})]
    >
    > Todd


    What I would ideally like is to be able to specify the size of the
    matrix and then have a random function populate the matrix with real
    integers or, eventually, complex numbers.

    Thanks for the guidance...
    --
    Posted via http://www.ruby-forum.com/.
     
    Jason Bornhoft, Oct 20, 2007
    #3
  4. On Oct 19, 2007, at 9:38 PM, Jason Bornhoft wrote:
    >> Not sure what you want exactly, but, maybe...
    >>
    >> require 'matrix'
    >> a, b = 2, 3
    >> m = Matrix[*(Array.new(a) {Array.new(b) {rand}})]
    >>
    >> Todd

    >
    > What I would ideally like is to be able to specify the size of the
    > matrix and then have a random function populate the matrix with real
    > integers or, eventually, complex numbers.
    >
    > Thanks for the guidance...


    So something like:

    require 'matrix'
    def some_random_function
    # make something up, perhaps something complex
    end
    rows, columns = 2, 3
    matrix = Matrix[*(Array.new(rows) {Array.new(columns)
    { some_random_function }})]

    And, yes, that just about exactly what you were already given. ;-)

    -Rob

    Rob Biedenharn http://agileconsultingllc.com
     
    Rob Biedenharn, Oct 20, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. globalrev
    Replies:
    4
    Views:
    778
    Gabriel Genellina
    Apr 20, 2008
  2. Alex Untitled
    Replies:
    11
    Views:
    664
    Giampiero Zanchi
    Nov 16, 2009
  3. PerlFAQ Server

    FAQ 4.10 Why aren't my random numbers random?

    PerlFAQ Server, Feb 12, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    225
    PerlFAQ Server
    Feb 12, 2011
  4. PerlFAQ Server

    FAQ 4.10 Why aren't my random numbers random?

    PerlFAQ Server, Apr 27, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    257
    PerlFAQ Server
    Apr 27, 2011
  5. VK
    Replies:
    15
    Views:
    1,190
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page