]> gitweb.michael.orlitzky.com - octave.git/blobdiff - rank_k_approximation.m
Check for the easy case in rank_k_approximation().
[octave.git] / rank_k_approximation.m
index ff42f589c7a33e0eb09f1422ea43f10317b7d46a..9883084d479b1cb71d290ceb17281e82b1d56101 100644 (file)
@@ -14,6 +14,15 @@ function Ak = rank_k_approximation(A,k)
   %
   %   - ``Ak`` -- The rank-k approximation to ``A``.
   %
+  [m,n] = size(A);
+
+  if (k >= min(m,n))
+    % We're keeping greater than or equal to the maximum number of
+    % singular values that can exist.
+    Ak = A;
+    return;
+  end
+
   [U, S, V] = svds(A, k);
   Ak = U*S*V';
 end