9.3.16 Producing random matrices: randmatrix ranm randMat
The randmatrix command produces random vectors and matrices.
(See also Section 6.27.28 and Section 9.3.15.)
ranm and randMat are synonyms for randmatrix.
-
randmatrix takes one mandatory argument and three
optional arguments:
-
n, an integer.
- Optionally, p, an integer.
- Optionally, a, an integer.
- Optionally, a..b, a range.
- Optionally, distr, a distribution, which can be one
of:
-
’rand(n)’ (see Section 9.3.1).
- ’binomial(n,p)’, ’binomial,n,p’
or ’randbinomial(n,p)’, for a binomial distribution
(see Section 9.4.3 and Section 9.3.3).
- ’multinomial(P,K)’,
’multinomial,P,K’ or
’randmultinomial(P,K)’ for a multinomial distribution
(see Section 9.4.5 and Section 9.3.4).
- ’poisson(λ)’, ’poisson,
λ’ or ’randpoisson(λ)’ for a Poisson
distribution (see Section 9.4.6 and
Section 9.3.5).
- ’normald(µ,σ)’,
’normald,µ,σ’ or ’randnorm(µ,σ)’
for a normal distribution (see Section 9.4.7 and
Section 9.3.6).
- ’exp(a)’, ’exp,a’ or
’randexp(a)’ for an exponential distribution (see
Section 9.4.15 and Section 9.3.13).
- ’fisher(n,m)’, ’fisher,n,m’ or
’randfisher(n,m)’ for a Fisher-Snédécor
distribution (see Section 9.4.10 and
Section 9.3.9).
Note that distr is in quotes.
- randmatrix(n) returns a vector of
length n whose elements are integers chosen randomly from
[−99,−98,…,98,99] with equal probability.
- randmatrix(n,p) returns an n× p matrix
whose elements are integers chosen randomly from [−99,99] with
equal probability.
- randmatrix(n,p,a) returns an n× p matrix
whose elements are integers chosen randomly from [0,a) (or (a,0]
is a is negative) with equal probability.
- randmatrix(n,p,a..b) returns an n× p
matrix whose elements are real numbers chosen randomly from
[a,b) with equal probability.
- randmatrix(n,p,distr)
returns an n× p matrix whose elements are numbers chosen
randomly according to distribution distr.
Examples.