Mercurial > matrix-functions
comparison toolbox/rando.m @ 2:c124219d7bfa draft
Re-add the 1995 toolbox after noticing the statement in the ~higham/mctoolbox/ webpage.
author | Antonio Pino Robles <data.script93@gmail.com> |
---|---|
date | Thu, 07 May 2015 18:36:24 +0200 |
parents | 8f23314345f4 |
children |
comparison
equal
deleted
inserted
replaced
1:e471a92d17be | 2:c124219d7bfa |
---|---|
1 function A = rando(n, k) | |
2 %RANDO Random matrix with elements -1, 0 or 1. | |
3 % A = RANDO(N, K) is a random N-by-N matrix with elements from | |
4 % one of the following discrete distributions (default K = 1): | |
5 % K = 1: A(i,j) = 0 or 1 with equal probability, | |
6 % K = 2: A(i,j) = -1 or 1 with equal probability, | |
7 % K = 3: A(i,j) = -1, 0 or 1 with equal probability. | |
8 % N may be a 2-vector, in which case the matrix is N(1)-by-N(2). | |
9 | |
10 if nargin < 2, k = 1; end | |
11 | |
12 m = n(1); % Parameter n specifies dimension: m-by-n. | |
13 n = n(max(size(n))); | |
14 | |
15 if k == 1 % {0, 1} | |
16 A = floor( rand(m,n) + .5 ); | |
17 elseif k == 2 % {-1, 1} | |
18 A = 2*floor( rand(m,n) + .5 ) - 1; | |
19 elseif k == 3 % {-1, 0, 1} | |
20 A = round( 3*rand(m,n) - 1.5 ); | |
21 end |