Uploaded by anais.pm2800

matlab5

advertisement
Anais Moran
Matlab # 5 : QR Factorization
Problem 1
%Matrix A
qrdat
A = 4×3
3
1
-1
3
B = 4×2
3
1
-1
3
C = 5×3
1
-1
-1
1
1
D = 3×5
1
2
5
-5
1
5
-7
1
1
-2
8
-5
1
5
-7
2
1
4
-4
2
5
-4
-3
7
1
-1
1
-4
-1
4
-3
1
-4
7
1
2
1
[Q R] = qr(A)
Q = 4×4
-0.6708
-0.2236
0.2236
-0.6708
R = 4×3
-4.4721
0
0
0
-0.2236
-0.6708
-0.6708
0.2236
-0.6708
0.2236
0.2236
0.6708
8.9443
-4.4721
0
0
-6.7082
2.2361
4.4721
0
0.2236
-0.6708
0.6708
0.2236
format long, Q' *Q
ans = 4×4
1.000000000000000
0.000000000000000
0.000000000000000
-0.000000000000000
0.000000000000000
1.000000000000000
0.000000000000000
0
0.000000000000000
0.000000000000000
1.000000000000000
-0.000000000000000
%looking at the output,
%this resembles an
%identify Matrix
Q*R, A
1
-0.000000000000000
0
-0.000000000000000
1.000000000000000
ans = 4×3
3.000000000000000
1.000000000000000
-1.000000000000000
3.000000000000000
A = 4×3
3
-5
1
1
1
1
-1
5
-2
3
-7
8
-5.000000000000004
0.999999999999999
5.000000000000000
-7.000000000000002
1.000000000000003
1.000000000000000
-2.000000000000000
8.000000000000000
%Matrices are identical
format short
%Matrix B
[Q R]= qr(B)
Q = 4×4
-0.6708
-0.2236
0.2236
-0.6708
R = 4×2
-4.4721
0
0
0
-0.2236
-0.6708
-0.6708
0.2236
0.2236
-0.6708
0.6708
0.2236
-0.6708
0.2236
0.2236
0.6708
-0.5000
-0.0000
-0.5000
0.5000
-0.5000
-0.5000
0.0000
-0.5000
-0.5000
0.5000
-0.0236
0.8000
0.0236
0.4236
0.4236
-0.5472
-0.4000
0.5472
0.3472
0.3472
2.2361
-6.0000
0
0
0
-8.9443
2.0000
-4.0000
0
0
-5.1121
6.2500
-1.8257
-1.3646
8.9443
-4.4721
0
0
%Matrix C
[Q R] = qr(C)
Q = 5×5
-0.4472
0.4472
0.4472
-0.4472
-0.4472
R = 5×3
-2.2361
0
0
0
0
%Matrix D
[Q R] = qr(D)
Q = 3×3
-0.1826
-0.3651
-0.9129
R = 3×5
-5.4772
0
0.1501
-0.9279
0.3412
-0.9717
-0.0747
0.2242
3.4689
-2.4427
1.4606
-4.8854
2
0
0
-0.0000
0.8969
-0.8969
Problem 2A
by hand
Problem 2B
When comparing Q1 and R1 with the Q and R that I calculated is that they are similar to the output recieved
the code of "[Q R] = qr( c ) The output overal was a 5 by 5 matrix. Next the Q calculted turned out to be a 5 by
3 matrix and the numbers that appeared in this matrix appreaed in the first three columns of the 5 by 5 matrix.
After that, the output of R was the same shape as the C generated code of a 5 by 3 and was as well an upper
triangle, again the same pattern showed up where the R caculated by the matlab was the first three columns
calculated by hand.
Problem 3
3
G = gs(C)
Matrix U with orthogonal columns:
U = 5×3
1
3
2
-1
0
0
-1
3
2
1
-3
2
1
3
-2
rational display:
U =
1
3
-1
0
-1
3
1
-3
1
3
2
0
2
2
-2
Problem 3B
G compares to the Matrix Q1 that Ive calculated by hand in question 2a since G produces a matlab code of
[1 3 2; -1 0 0; 1 -3 2; 1 3 -2], G matrices holds whole real numbers meanwhile Q1 holds fractions. Now going
to Theorem 11 causes the QR factorization to have orthogonalization of the columns in the matrix obviously
starting from the ifrst column. this doesnt show when being used on matlab due to becoming less orthogonal as
code continues.
Problem 4
The theorem for Qr factorization says that "if A is an m by n matrix with linearly independent columns, then
A can be factores as A = QR, where Q is an M by n matrix whose columns form an orthonormal basis for col
A and R is an n by n upper triangleular invertible matrix with positive enteries on its diagonal." This algorithm
multiplies A by the orthogonal matrices P1,P2 and so on and so forth until the product Pk, P2P1A resembles
or is equal to the matrix R which has a lower triangle filled with zeros. This also means Q is a transpose of of
the product Pk, P2P1A. Theorem 6 also shows up stating "An m by n matrix U has an orthonormal and only if
U^T * U = I" as well as Theorem 7 "Let U by an m by n matrix with orthonormal columns, and let x and y be in
R^n", these theorems pop up whenever there is a square matrix, which claim that any square matrix that has
orthonormal columns is a orthogonal matrix.
4
Download