diff scripts/linear-algebra/normest.m @ 9875:47f36dd27203

randomize initial guess in normest
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 26 Nov 2009 13:17:39 +0100
parents 87595d714005
children c69252eb2f2b
line wrap: on
line diff
--- a/scripts/linear-algebra/normest.m
+++ b/scripts/linear-algebra/normest.m
@@ -42,6 +42,10 @@
   e = norm (x);
   if (e > 0)
     [m, n] = size (A);
+    ## Randomize x to avoid bad guesses for important matrices.
+    ## FIXME: can we do something smarter?
+    x .*= randn (n, 1);
+    e = norm (x);
     x /= e;
     e0 = 0;
     while (abs (e - e0) > tol * e)