%aufgabe 4

t = (0.1:0.1:1.0)'
f = [100 34 17 12 9 6 5 4 4 2]'
A = [1./t 1./t.^2 exp(-(t-1)) exp(-2*(t-1))]

%grad = 0 mit Gauss
gamma_g = (A'*A)\(A'*f)

%qr-zerlegung
[Q R_s] = qr(A);
[m n] = size(A);

R = R_s(1:n,1:n);
U = Q(:,1:n);

gamma_qr = R\(U'*f)

%konditionszahlen
cond(A)
cond(A'*A)

%differenz gamma_g - gamma_qr
gamma_g - gamma_qr

t_f = linspace(0.1,1.0,1000)';
f_g = [1./t_f 1./t_f.^2 exp(-(t_f-1)) exp(-2*(t_f-1))] * gamma_g;
f_qr = [1./t_f 1./t_f.^2 exp(-(t_f-1)) exp(-2*(t_f-1))] * gamma_g;

semilogy(t,f,'O',t_f,f_g,'blue',t_f,f_qr,'red')
title('Aufgabe 4 Serie 8')
xlabel('t')
ylabel('f(t)')
