]> gitweb.michael.orlitzky.com - octave.git/blob - rank_k_approximation.m
ff42f589c7a33e0eb09f1422ea43f10317b7d46a
[octave.git] / rank_k_approximation.m
1 function Ak = rank_k_approximation(A,k)
2 %
3 % Compute the rank-k approximation to A from the ``k`` largest
4 % singular values of A.
5 %
6 % INPUT:
7 %
8 % - ``A`` -- The matrix to approximate.
9 %
10 % - ``k`` -- The rank of the resulting matrix; i.e. the number
11 % of (large) singular values to keep.
12 %
13 % OUTPUT:
14 %
15 % - ``Ak`` -- The rank-k approximation to ``A``.
16 %
17 [U, S, V] = svds(A, k);
18 Ak = U*S*V';
19 end