diff scripts/sparse/sprandsym.m @ 6252:738c97e101eb

[project @ 2007-01-24 19:58:46 by jwe]
author jwe
date Wed, 24 Jan 2007 19:58:46 +0000
parents 34f96dd5441b
children 2c85044aa63f
line wrap: on
line diff
--- a/scripts/sparse/sprandsym.m
+++ b/scripts/sparse/sprandsym.m
@@ -32,42 +32,40 @@
 ## @seealso{sprand, sprandn}
 ## @end deftypefn
 
-function S = sprandsym(n,d)
-  if nargin == 1
-    [i,j,v,nr,nc] = spfind(tril(n));
-    S = sparse(i,j,randn(size(v)),nr,nc);
-    S = S + tril(S,-1)';
-  elseif nargin == 2
-    m1 = floor(n/2);
-    n1 = m1 + 1;
+function S = sprandsym (n, d)
+  if (nargin == 1)
+    [i, j, v, nr, nc] = spfind (tril (n));
+    S = sparse (i, j, randn (size (v)), nr, nc);
+    S = S + tril (S, -1)';
+  elseif (nargin == 2)
+    m1 = floor (n/2);
+    n1 = m1 + rem (n, 2);
     mn1 = m1*n1;
-    k1 = round(d*mn1);
-    idx1=unique(fix(rand(min(k1*1.01,k1+10),1)*mn1))+1; 
-                # idx contains random numbers in [1,mn]
-  		# generate 1% or 10 more random values than necessary
-		# in order to reduce the probability that there are less than k
-		# distinct values;
-    		# maybe a better strategy could be used
-     		# but I don't think it's worth the price
-    k1 = min(length(idx1),k1);  # actual number of entries in S
-    j1 = floor((idx1(1:k1)-1)/m1);
+    k1 = round (d*mn1);
+    idx1 = unique (fix(rand(min(k1*1.01,k1+10),1)*mn1))+1; 
+    ## idx contains random numbers in [1,mn] generate 1% or 10 more
+    ## random values than necessary in order to reduce the probability
+    ## that there are less than k distinct values; maybe a better
+    ## strategy could be used but I don't think it's worth the price.
+    k1 = min (length (idx1), k1);  # actual number of entries in S
+    j1 = floor ((idx1(1:k1)-1)/m1);
     i1 = idx1(1:k1) - j1*m1;
 
-    n2 = ceil(n/2);
+    n2 = ceil (n/2);
     nn2 = n2*n2;
-    k2 = round(d*nn2);
-    idx2=unique(fix(rand(min(k2*1.01,k1+10),1)*nn2))+1; 
-    k2 = min(length(idx2),k2);
-    j2 = floor((idx2(1:k2)-1)/n2);
+    k2 = round (d*nn2);
+    idx2 = unique (fix (rand (min (k2*1.01, k1+10), 1)*nn2)) + 1; 
+    k2 = min (length (idx2), k2);
+    j2 = floor ((idx2(1:k2)-1)/n2);
     i2 = idx2(1:k2) - j2*n2;
 
-    if isempty(i1) && isempty(i2)
-      S = sparse(n,n);
+    if (isempty (i1) && isempty (i2))
+      S = sparse (n, n);
     else
-      S1 = sparse(i1,j1+1,randn(k1,1),m1,n1);
+      S1 = sparse (i1, j1+1, randn (k1, 1), m1, n1);
       S = [tril(S1), sparse(m1,m1); ...
 	   sparse(i2,j2+1,randn(k2,1),n2,n2), triu(S1,1)'];
-      S = S + tril(S,-1)';
+      S = S + tril (S, -1)';
     endif
   else
     print_usage ();