# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1316887584 18000 # Node ID 0257eb36e15a72983e083ec343fdf81c38550010 # Parent 658aa9fd866506694d33a56f8a3ee6eb53e5d286 Simplify a computation in sprandsym diff -r 658aa9fd8665 -r 0257eb36e15a scripts/sparse/sprandsym.m --- a/scripts/sparse/sprandsym.m Sat Sep 24 10:38:19 2011 -0400 +++ b/scripts/sparse/sprandsym.m Sat Sep 24 13:06:24 2011 -0500 @@ -65,13 +65,8 @@ ondiag = randperm (n, r); offdiag = randperm (n*(n - 1)/2, m); - ## Do five Newton iterations to solve n(n - 1)/2 = offdiag (this is the - ## row index) - x = sqrt (offdiag); - for ii = 1:5 - x = x - (x.^2 - x - 2*offdiag)./(2*x - 1); - endfor - i = floor(x); + ## solve with quadratic formula n^2 - n - 2*offdiag = 0 to get the row index + i = floor((1 + sqrt(1 + 8*offdiag))/2); i(i.^2 - i - 2*offdiag != 0) += 1; ## Column index