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: http://gitweb.michael.orlitzky.com/?p=octave.git;a=commitdiff_plain;h=b39f6d3f6aaaebe891c09a8923547f25c2d43b84;hp=7240c54725b82c037dfb6e43bedefbb1bf47a0bc 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