From: Michael Orlitzky Date: Sun, 5 May 2013 01:11:13 +0000 (-0400) Subject: Check for the easy case in rank_k_approximation(). X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=b39f6d3f6aaaebe891c09a8923547f25c2d43b84;p=octave.git Check for the easy case in rank_k_approximation(). --- diff --git a/rank_k_approximation.m b/rank_k_approximation.m index ff42f58..9883084 100644 --- a/rank_k_approximation.m +++ b/rank_k_approximation.m @@ -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