% m1 --- Initialization
global vv s2 c
fprintf('\nThe matrix\n')
A = [ 10 2 3
      4 13 6
      7 8 10 ]
x = [ 7 5 3 ]';
fprintf('Let x = ')
vprint(x);
c = x'*x;
fprintf('\nThe energy in x = %g,\n',c)
y = A*x;
fprintf('\nand y = A x = ')
vprint(y);
[q1, sval, p] = svd(A);
s1 = diag(sval);
if all(s1)       % If s1(i) ~= 0 for all i, then put r = length(s1)
  r = length(s1);
else
  r = find(s1 == 0);
end
fprintf('\nRank(A) = %g\n',r)
s = s1(1:r);
fprintf('\nThe positive singular values are:\n')
vprint(s);
q = q1(:,1:r);
s2 = s.^2;
vv = s.*(q'*y);
fracc = .9;
c = fracc*c;
fprintf('\nLet c be %g%% of the energy in x.  Then c = %g\n\n',fracc,c)
