Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Matrix question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60304] Re: [mg60287] Matrix question
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sat, 10 Sep 2005 22:36:23 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Needs["DiscreteMath`Combinatorica`"]

randommatrix[n_, p_] :=
  Module[{worklist, numones = Floor[p n^2]},
    worklist = Join[Array[1 &, numones], Array[0 &, n^2 - numones]];
    worklist = Part[worklist, Ordering[RandomPermutation[n^2]]];
    Partition[worklist, n]]

randommatrix[4, 0.5] // MatrixForm

First I made an array of the required number of 1's join to the remainder
zeros. Then I made a random permutation of the list. Then I partitioned the
list into rows.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/



From: sandog [mailto:sandog at mail.gr]
To: mathgroup at smc.vnet.net


i want to create a NxN matrix with zeros but i want a percentage of the
matrix spots to be one at random spots any idea? cause i have no clue how to
do that.
Any help appreciated thx .





  • Prev by Date: Generate a palette with a FrontEnd Token
  • Next by Date: Re: Switching to Mac caused 20x slowdown - please help!
  • Previous by thread: Re: Matrix question
  • Next by thread: Re: Matrix question