Re: random matrix initialisation...
- To: mathgroup at smc.vnet.net
- Subject: [mg37610] Re: [mg37576] random matrix initialisation...
- From: Tomas Garza <tgarza01 at prodigy.net.mx>
- Date: Wed, 6 Nov 2002 06:54:36 -0500 (EST)
- References: <200211051001.FAA14245@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Try this:
In[1]:=
<< "DiscreteMath`Combinatorica`"
In[2]:=
bigX[m_, n_] := Module[
{st = Join[Table[1, {n}], Table[0, {m^2 - n}]]},
Partition[st[[RandomPermutation[m^2]]], m]]
In[3]:=
bigX[4, 3]
Out[3]=
{{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 1}, {0, 1, 0, 0}}
In[4]:=
bigX[4, 3]
Out[4]=
{{0, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}
Tomas Garza
Mexico City
----- Original Message -----
From: "Manuel Marques-Pita" <manuxu at mac.com>
To: mathgroup at smc.vnet.net
Subject: [mg37610] [mg37576] random matrix initialisation...
>
> hello,
>
> i have a question regarding matrices. searched on the web and forums
> but maybe due to using wrong keywords i am not finding an answer...
>
> i need a way or function X to initialise matrices in mathematica such
> that each time i call X i get a matrix with a predetermined number of
> elements initialised as "1" and the rest as "0"
>
> examples
>
> X(4,3)
>
> {{0,0,0,0}, {0,0,1,0}, {0,0,0,1}, {1,0,0,0}}
>
> again X(4,3)
>
> {{1,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,1,0,0}}
>
> etc.. (first argument means that the matrix is 4x4 and second means
> that there should be 3 "1's" present in the matrix
>
> any help, pointers, etc will be appreciated!
>
> thanks a lot
>
> m
>
> --
>
>
- References:
- random matrix initialisation...
- From: Manuel Marques-Pita <manuxu@mac.com>
- random matrix initialisation...