% richiede il toolbox Regularization Tools di P.C. Hansen

n = 20;
[A b sol] = baart(n);
ds = 1e-8;
b = b + ds/norm(b)*randn(n,1);

[U s V] = csvd(A);
figure(2)
y = U'*b;
semilogy([abs(y) s],'o')

figure(3)
kg = gcv(U,s,b,'tsvd')
figure(4)
kl = l_curve(U,s,b,'tsvd')

k = input('k = ');

while k>0
	x = tsvd(U,s,V,b,k);
	errore = norm(sol-x)
	figure(1)
	plot([sol x])
	ylim([0 0.5])
	k = input('k = ');
end
