1 function Ak = rank_k_approximation(A,k)
3 % Compute the rank-k approximation to A from the ``k`` largest
4 % singular values of A.
8 % - ``A`` -- The matrix to approximate.
10 % - ``k`` -- The rank of the resulting matrix; i.e. the number
11 % of (large) singular values to keep.
15 % - ``Ak`` -- The rank-k approximation to ``A``.
20 % We're keeping greater than or equal to the maximum number of
21 % singular values that can exist.
26 [U, S, V, flag] = svds(A, k);
31 error('Could not compute the rank-k approximation.');