Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Create matrix with random numbers

Reply
Thread Tools

Create matrix with random numbers

 
 
Jason Bornhoft
Guest
Posts: n/a
 
      10-19-2007
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/.

 
Reply With Quote
 
 
 
 
Todd Benson
Guest
Posts: n/a
 
      10-19-2007
On 10/19/07, Jason Bornhoft <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
 
Jason Bornhoft
Guest
Posts: n/a
 
      10-20-2007
> 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/.

 
Reply With Quote
 
Rob Biedenharn
Guest
Posts: n/a
 
      10-20-2007
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
http://www.velocityreviews.com/forums/(E-Mail Removed)



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 4.10 Why aren't my random numbers random? PerlFAQ Server Perl Misc 0 04-27-2011 04:00 AM
FAQ 4.10 Why aren't my random numbers random? PerlFAQ Server Perl Misc 0 02-12-2011 11:00 PM
Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2) VK Javascript 15 05-02-2010 03:43 PM
How do I get a random number between two random numbers? Alex Untitled Ruby 11 11-16-2009 09:45 AM
random.random(), random not defined!? globalrev Python 4 04-20-2008 08:12 AM



Advertisments