function ex11()
xi = [1 2 3 4]';
yi = [3 2 3 7]';

% Systemgleichung
A = [ones(4,1), xi, xi.^2]
b = yi

% QR-Zerlegung
s1 = A(:,1);
v1 = s1 - norm(s1)*[1 0 0 0]'
Q1 = eye(4) - (2/(v1'*v1))*(v1*v1') 
A1 = Q1*A

s2 = [0; A1(2:4,2)]
v2 = s2 - norm(s2)*[0 1 0 0]'
Q2 = eye(4) - (2/(v2'*v2))*(v2*v2') 
A2 = Q2*A1

s3 = [0;0; A2(3:4,3)]
v3 = s3 - norm(s3)*[0 0 1 0]'
Q3 = eye(4) - (2/(v3'*v3))*(v3*v3') 
A3 = Q3*A2

R = A3
Q = Q1'*Q2'*Q3'

% Lösung der Gleichung
tt = Q'*b;
b1 = tt(1:3)
b2 = tt(4)

R1 = R(1:3,:)
x = R1 \ b1

% Plotten
poly = x(3:-1:1);
xp = 0.9:0.01:4.1;
yp = polyval(poly, xp);
plot(xi, yi, "r*", xp, yp, "k-")

F = getframe(gcf);
imwrite(F.cdata, "bild29.png");
