From b39f6d3f6aaaebe891c09a8923547f25c2d43b84 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sat, 4 May 2013 21:11:13 -0400 Subject: [PATCH] Check for the easy case in rank_k_approximation(). --- rank_k_approximation.m | 9 +++++++++ 1 file changed, 9 insertions(+) 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 -- 2.43.2