%% Fix Convergence Problem
% Create a sparse diagonal matrix and calculate the six largest singular values.

A = diag(sparse([1e4*ones(1, 8) 1e4:-1:1]));
s = svds(A)

% The svds algorithm produces a warning since the maximum number of iterations were performed but the tolerance could not be met.
%
% The most effective way to address convergence problems is to increase the maximum size of the Krylov subspace used in the calculation by using a larger value for 'SubspaceDimension'. Do this by passing in the name-value pair 'SubspaceDimension' with a value of 60.

s = svds(A,6,'largest','SubspaceDimension',60)

% Copyright 2012 The MathWorks, Inc.