X-Git-Url: http://gitweb.michael.orlitzky.com/?p=octave.git;a=blobdiff_plain;f=rank_k_approximation.m;fp=rank_k_approximation.m;h=ff42f589c7a33e0eb09f1422ea43f10317b7d46a;hp=0000000000000000000000000000000000000000;hb=79deafc20bc4cb3704f7f2cfcf845ed09d31eee3;hpb=6208d54caedc1bab6bb794a8ad3dd8e72c28d342 diff --git a/rank_k_approximation.m b/rank_k_approximation.m new file mode 100644 index 0000000..ff42f58 --- /dev/null +++ b/rank_k_approximation.m @@ -0,0 +1,19 @@ +function Ak = rank_k_approximation(A,k) + % + % Compute the rank-k approximation to A from the ``k`` largest + % singular values of A. + % + % INPUT: + % + % - ``A`` -- The matrix to approximate. + % + % - ``k`` -- The rank of the resulting matrix; i.e. the number + % of (large) singular values to keep. + % + % OUTPUT: + % + % - ``Ak`` -- The rank-k approximation to ``A``. + % + [U, S, V] = svds(A, k); + Ak = U*S*V'; +end