Sei sulla pagina 1di 7

Ejericicio 1

Demostrar que (: , + 1: ) forman una base ortonormal del espacio (()).


Demostracin.Sea = una factorizacin QR completa.
1
2

[1 |2 | . | ] = [1 2 +1 . ]
0

[0]
=
Multiplicamos por la transpuesta conjugada = =
Se tiene

1
1
2
2

[1|2 | . | ] =

+1
0

[
[ ]
0]
1 1
2 1

+1
1

1
[

1 2
2 2

2

+1
2

+1
2

1
1
1
2

+1

0

[
]
0]

Entonces:

+1
= 0

= 0

= 1, . . .
Por lo anterior:
{+1 , . , } (())
Se observa que +1 , . , son vectores ortogonales a cualquier columna de
A.

Por otro lado, vamos obtener la dimensin del espacio (())


Definimos (()) como:
(()) = { / = 0,
= 1, . . , }

dim(()) + dim ((()) ) =

+ dim ((()) ) =

dim ((()) ) =

Por ltimo, definimos un espacio W como:


= +1 , ,
Al ser {+1 , . , } un conjunto de vectores ortogonales, podemos
asegurar que son linealmente independiente. Entonces {+1 , . , } es
una base de W.

Se saba que
{+1 , . , } (())
Entonces
(())
Adems
dim() = = dim(() )
Por lo tanto
= (())
Concluimos que {+1 , . , } forman una base ortonormal de (()) .

Ejercicio 3.Cuestion 3.2 libro de demmel


Datos de entrada para el cdigo QRStability.m
m,n= nmero de filas y columnas
muestras= nmero de matrices muestra
cnd=nmero de condicionamiento

Ejemplo 1

>> m=6
>> n=4
>> samples=20
>> cnd=10000000
Grafico que representa la diferencia . La ortogonalidad

Se observa que el error ms pequeo y estable esta dado por el mtodo


de Householder, cumple que
~()
Se observa que para el Mtodo Gram Schmidt modificado el erro es ms
grande que para Householder pero menor que el mtodo CGS.
~()2 ()
Se observa que para el Mtodo Gram Schmidt clsico cumple:
~()2 ()2

max( norm(A-Q*R)/norm(A) ) for Householder QR = 7.3938e-16


max( norm(A-Q*R)/norm(A) ) for CGS

= 1.3381e-16

max( norm(A-Q*R)/norm(A) ) for MGS

= 1.1465e-16

Los tres metodos son backward estable.


Podemos observer que se cumple:


~()

%
%
%
%
%
%
%

Matlab code QRStability.m


For "Applied Numerical Linear Algebra",
Written by James Demmel, Aug 2, 1996;
Modified, Jun 2, 1997

Question 3.2

Compare the numerical stability of 3 algorithms for computing


the QR decomposition:

%
QR using Householder transformations
%
CGS (Classical Gram-Schmidt)
%
MGS (Modified Gram-Schmidt)
%
% Inputs:
%
%
m, n = numbers of rows, columns in test matrices
%
m should be at least n
%
samples = number of test matrices to generate
%
samples should be at least 1
%
cnd = condition number of test matrices to generate
%
(ratio of largest to smallest singular value)
%
cnd should be at least 1
%
% Outputs:
%
%
For each algorithm, the maximum value of the residual
%
norm(A-Q*R)/norm(A), which should be around
%
macheps = 1e-16 for a stable algorithm
%
%
For each algorithm, a plot (versus sample number)
%
of the orthogonality norm(Q'*Q-I), which should
%
also be around macheps if the computed Q is orthogonal
%
and the algorithm is stable
%
residual = [];
orth = [];
% Generate samples random matrices
for exnum = 1:samples,
% Generate random matrix A, starting with the SVD of a random matrix
A=randn(m,n);
[u,s,v]=svd(A);
% Let singular values range from 1 to cnd, with
% uniformly distributed logarithms
sd = [1, cnd, exp(rand(1,n-2)*log(cnd))];
s = diag(sd);
A=u(:,1:n)*s*v';
% Perform CGS (A = Qcgs*Rcgs) and MGS (A = Qmgs*Rmgs)
Rcgs=[]; Rmgs=[];
Qcgs=[]; Qmgs=[];
for i=1:n,
Qcgs(:,i)=A(:,i);
Qmgs(:,i)=A(:,i);
for j=1:i-1,
Rcgs(j,i) = (Qcgs(:,j))'*A(:,i);
Qcgs(:,i) = Qcgs(:,i) - Rcgs(j,i)*Qcgs(:,j);
Rmgs(j,i) = (Qmgs(:,j))'*Qmgs(:,i);
Qmgs(:,i) = Qmgs(:,i) - Rmgs(j,i)*Qmgs(:,j);
end
Rcgs(i,i) = norm(Qcgs(:,i));
Rmgs(i,i) = norm(Qmgs(:,i));
Qcgs(:,i) = Qcgs(:,i) / Rcgs(i,i);
Qmgs(:,i) = Qmgs(:,i) / Rmgs(i,i);
end
% Perform Householder QR
[Qhouse,Rhouse]=qr(A,0);
% Compute residuals for each algorithm (cnd = norm(A))
residual(exnum,1:3) = ...
[ norm(A-Qhouse*Rhouse), norm(A-Qcgs*Rcgs), norm(A-Qmgs*Rmgs)
]/cnd;
% Compute orthogonality of Q for each algorithm

ee = eye(n);
orth(exnum,1:3) = ...
[ norm(Qhouse'*Qhouse-ee), norm(Qcgs'*Qcgs-ee), norm(Qmgs'*Qmgsee) ];
end
% Limit orth to 1 (any larger error is as bad) so it shows up on plot
orth = min(orth,ones(size(orth)));
% Print max residuals
disp(['max( norm(A-Q*R)/norm(A) ) for Householder QR = ', ...
num2str(max(residual(:,1)))])
disp(['max( norm(A-Q*R)/norm(A) ) for CGS
= ', ...
num2str(max(residual(:,2)))])
disp(['max( norm(A-Q*R)/norm(A) ) for MGS
= ', ...
num2str(max(residual(:,3)))])
% Plot orthogonalities
clf
% make sure orthogonalities are at least eps to avoid log(0)
orth = max(orth,eps);
semilogy((1:samples),orth(:,1),'b*', ...
(1:samples),orth(:,2),'r*', ...
(1:samples),orth(:,3),'g*')
axis([1 samples 1e-16 1])
grid
ylabel('orthogonality')
xlabel(['test matrix number, condition num =',num2str(cnd)])
title('Orthogonality of Q for CGS (red), MGS (green), Householder
(blue)')

Potrebbero piacerti anche