MathGroup Archive 2005

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

Search the Archive

Re: Matrix question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60337] Re: Matrix question
  • From: "Dr. Wolfgang Hintze" <weh at snafu.de>
  • Date: Tue, 13 Sep 2005 06:07:35 -0400 (EDT)
  • References: <dfudth$1qo$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

understanding that you are looking for a matrix in which a percentage p 
of random positions has the value 1 whereas the rest is 0 (same 
understanding as David Park and Bill Rowe) my solution (very 
straighforward, working without any package and for Version 4) is

Parameters of the problem

n = 10;
p = 0.3;

Init

m = Floor[n^2*p];
A = Array[0 & , {n, n}];

Select a set of m random positions {i,j}

r = {};
While[Length[r] < m, AppendTo[g, {1 + Random[Integer, n - 1], 1 + 
Random[Integer, n - 1]}];
    r = Union[r]]

Assign 1 to the random positions in matrix A

Do[A[[r[[i,1]],r[[i,2]]]] = 1, {i, 1, Length[r]}]

MatrixForm[A]

Regards,
Wolfgang

sandog wrote:

> 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: Re: Precedence
  • Next by Date: Re: Timed Notebooks for Student Take-home examinations
  • Previous by thread: Re: Matrix question
  • Next by thread: Re: Condition for pure functions