Praktikum Metode Komputasi (Vector Spaces) Vina Apriliani January 17, 016 Soal Latihan MATLAB Bab 3 Buku Leon Aljabar Linear Berikut 1 Soal Latihan MATLAB Bab 3 Buku Leon Aljabar Linear yang saya ambil untuk ditulis dengan LaTeX dan harus dikerjakan ( digit terakhir NRP modulo jumlah soal di Latihan) yaitu Soal Nomor (): Rank-Deficient Matrices In this exercise we consider how to use MATLAB to generate matrices with specified ranks. a In general, if A is an m x n matrix with rank r, then r <= min(m,n). Why? Explain. If the entries of A are random numbers, we would expect that r = min(m,n). Why? Explain. Check this out by generating random 6 x 6, 8 x 6, and 5 x 8 matrices and using the MATLAB command rank to compute their ranks. Whenever the rank of an m x n matrix equals min(m,n), we say that the matrix has full rank. Otherwise, we say that the matrix is rank deficient. Jika A adalah matriks m x n dengan rank r, maka r <= min(m,n) karena rank r adalah dimensi dari ruang baris sehingga rank r <= m, sedangkan dimensi ruang baris = dimensi ruang kolom sehingga rank r <= min(m,n). (Teorema) Jika entri dari matriks A adalah bilangan acak, kita dapat menduga bahwa r=min(m,n) karena antar baris tidak pernah merupakan kelipatan satu dengan yang lain. Generating random 6 x 6, 8 x 6, 5 x 8 matrices and compute their ranks using MATLAB command: A = rand(6,6) 0.8147 0.785 0.957 0.79 0.6787 0.7060 0.9058 0.5469 0.4854 0.9595 0.7577 0.0318 A = 0.170 0.9575 0.8003 0.6557 0.7431 0.769 0.9134 0.9649 0.1419 0.0357 0.39 0.046 0.634 0.1576 0.418 0.8491 0.6555 0.0971 0.0975 0.9706 0.9157 0.9340 0.171 0.835 1
rank(a) = 6 B = rand(8,6) 0.6948 0.1869 0.6551 0.7513 0.1493 0.1966 0.3171 0.4898 0.166 0.551 0.575 0.511 0.950 0.4456 0.1190 0.5060 0.8407 0.6160 B = 0.0344 0.6463 0.4984 0.6991 0.543 0.4733 0.4387 0.7094 0.9597 0.8909 0.8143 0.3517 0.3816 0.7547 0.3404 0.9593 0.435 0.8308 0.7655 0.760 0.5853 0.547 0.993 0.5853 0.795 0.6797 0.38 0.1386 0.3500 0.5497 rank(b) = 6 C = rand(5,8) 0.81 0.7317 0.7447 0.656 0.4868 0.5108 0.8116 0.550 0.0154 0.6477 0.1890 0.780 0.4359 0.8176 0.538 0.65 C = 0.0430 0.4509 0.6868 0.0811 0.4468 0.7948 0.3507 0.5870 0.1690 0.5470 0.1835 0.994 0.3063 0.6443 0.9390 0.077 0.6491 0.963 0.3685 0.7757 0.5085 0.3786 0.8759 0.301 rank(c) = 5 b MATLAB s rand and round commands can be used to generate random m x n matrices with integer entries in a given range [a,b]. This can be done with a command of the form For example, the command A = round((b-a)*rand(m,n))+a A = round(4*rand(6,8))+3 will generate a 6 x 8 matrix whose entries are random integers in the range from 3 to 7. Using the range [1,10], create random integer 10 x 7, 8 x 1, and 10 x 15 matrices and in each case check the rank of the matrix. Do these integer matrices all have full rank? Random integer 10 x 7 matrix in the range [1,10]: A1 = round(9*rand(10,7))+1
8 7 7 5 3 8 9 10 1 1 4 7 3 10 9 3 8 7 6 9 5 9 1 8 7 A1 = 7 8 7 3 9 8 8 5 5 10 4 5 8 7 5 10 6 6 9 5 4 7 4 10 8 7 10 7 6 10 10 3 1 8 3 3 rank(a1) = 7 This integer matrix has full rank because r = min(10,7) = 7. Random integer 8 x 1 matrix in the range [1,10]: A = round(9*rand(8,1))+1 9 7 8 9 4 5 4 5 4 3 5 8 6 5 5 6 1 8 4 4 6 3 3 9 5 9 8 3 8 6 5 6 9 10 8 6 A = 10 5 9 6 1 3 1 5 6 3 5 3 4 6 1 4 7 8 8 9 5 5 3 9 6 7 6 8 3 9 3 4 3 4 8 8 8 10 9 3 7 3 9 rank(a) = 8 This integer matrix has full rank because r = min(8,1) = 8. Random integer 10 x 15 matrix in the range [1,10]: A3 = round(9*rand(10,15))+1 3
9 7 4 6 9 3 5 4 5 7 4 9 7 10 8 10 8 7 6 6 3 4 6 5 7 4 9 7 8 6 7 8 8 7 3 3 5 3 4 7 8 6 8 5 8 6 5 5 6 5 10 7 3 6 5 3 6 9 7 3 4 6 10 1 A3 = 1 3 7 4 4 8 4 4 9 3 3 6 9 7 8 3 7 6 8 8 5 8 5 5 6 8 6 9 5 6 9 1 10 1 3 5 6 3 3 7 1 3 8 8 5 1 7 1 7 5 4 9 9 3 9 5 7 9 5 6 8 3 3 4 9 3 10 8 7 3 9 6 3 5 rank(a3) = 10 This integer matrix has full rank because r = min(10,15) = 10. c Suppose that we want to use MATLAB to generate matrices with less than full rank. It is easy to generate matrices of rank 1. If x and y are nonzero vectors in R m and R n, respectively, then A = xy T will be an m x n matrix with rank 1. Why? Explain. Verify this in MATLAB by setting x = round(9*rand(8,1))+1, y = round(9*rand(6,1))+1 and using these vectors to construct an 8 x 6 matrix A. Check the rank of A with the MATLAB command rank. Jika x dan y adalah vektor-vektor taknol masing-masing di R m dan R n, maka A = xy T akan menjadi matriks m x n dengan rank 1 karena setiap baris pada matriks A (baris ke- sampai baris ke-m) merupakan kelipatan baris pertama, dapat dilihat dari bentuk eselon baris tereduksi dari matriks A. Construct an 8 x 6 matrix A: x = round(9*rand(8,1))+1 4
5 8 x = 3 5 8 8 y = round(9*rand(6,1))+1 5 y = 6 5 7 7 10 5 30 5 35 35 16 40 48 40 56 56 4 10 1 10 14 14 A = x y = 4 10 1 10 14 14 6 15 18 15 1 1 10 5 30 5 35 35 16 40 48 40 56 56 16 40 48 40 56 56 d In general, rank(a) = 1 rank(ab) <= min(rank(a),rank(b)) (1) (See Exercise 8 in Section 6.) If A and B are noninteger random matrices, the relation (1) should be an equality. Generate an 8 x 6 matrix A by setting X = rand(8,), Y = rand(6,), A = X*Y What would you expect the rank of A to be? Explain. Test the rank of A with MATLAB. X = rand(8,) 5
0.90 0.4897 0.4317 0.3395 0.0155 0.9516 X = 0.9841 0.903 0.167 0.057 0.106 0.7379 0.374 0.691 0.1981 0.48 Y = rand(6,) 0.5479 0.6663 0.947 0.5391 Y = 0.4177 0.6981 0.9831 0.6665 0.3015 0.1781 0.7011 0.180 0.4863 0.5393 0.4638 0.6134 0.175 0.674 0.467 0.5900 0.4173 0.6506 0.1906 0.3461 0.646 0.576 0.6708 0.6495 0.174 0.137 A = X Y = 1.154 1.439 1.0536 1.5808 0.4606 0.8077 0.167 0.1860 0.1066 0.1994 0.0598 0.139 0.5499 0.4979 0.5595 0.596 0.1635 0.1689 0.3834 0.496 0.3434 0.5455 0.160 0.955 0.3903 0.4147 0.3779 0.4766 0.1350 0.1930 Menurut dugaan saya, rank(a) = karena matriks X dan matriks Y adalah matriks yang berisi bilangan acak takbulat sehingga rank(x)= dan rank(y)=rank(y )=. Oleh karena itu, persamaan (1) berlaku sehingga rank(a)=rank(x*y )=min(rank(x),rank(y ))=min(,)=. Test the rank of A with MATLAB: rank(a) = rank(x) = rank(y) = rank(y ) = e Use MATLAB to generate matrices A, B, and C such that (i) A is 8 x 8 with rank 3. (ii) B is 6 x 9 with rank 4. (iii) C is 10 x 7 with rank 5. 6
A = rand(8,3)*(rand(8,3)) 0.083 0.6345 0.180 0.1190 0.688 0.053 0.804 0.8018 1.4601 0.7884 0.914 0.9057 1.593 1.0568 0.7963 0.853 0.966 1.0366 0.6461 0.858 1.046 0.6704 0.79 0.8407 A = 1.3117 0.639 0.804 0.808 1.3843 0.944 0.6347 0.6607 0.59 0.095 0.3044 0.1700 0.5791 0.411 0.904 0.815 0.9719 0.6895 0.5750 0.4090 1.3615 0.778 1.0466 1.0381 0.9671 0.5660 0.5787 0.4440 1.308 0.7514 0.883 0.861 1.4447 0.7678 0.889 0.770 1.683 1.085 0.9693 0.981 rank(a) = 3 B = rand(6,4)*(rand(9,4)) 0.7531 1.068 0.7318 0.6118 0.7794 0.718 0.3805 0.4644 0.6317 1.0753 0.7531 0.893 0.376 0.7485 0.6787 0.393 0.4070 0.613 B = 1.67 1.3797 1.1597 0.9838 1.857 1.655 0.6159 0.6135 0.8341 0.5357 0.4910 0.4839 0.393 0.5376 0.5356 0.396 0.165 0.316 1.1837 1.553 1.0144 1.0303 1.1841 1.431 0.7365 0.775 0.7685 1.464 1.7888 1.301 1.3010 1.5305 1.593 0.8581 0.833 0.9349 rank(b) = 4 C = rand(10,5)*(rand(7,5)) 1.6690 1.1011 1.149 1.5487 1.3678 1.5599 0.8984 1.6030 1.387 1.903 1.4143 1.40 1.7860 0.8303 1.4676 0.9909 1.1964 1.17 1.4084 1.5996 0.6791 1.737 1.5759 1.3959 1.8946 1.3098 1.707 0.8481 C = 1.569 1.18 1.1454 1.5636 1.335 1.5670 0.8530 1.6974 1.398 1.4 1.6564 1.5433 1.8807 1.044 0.9967 0.6554 0.7303 0.9195 0.8361 0.9369 0.4867.3488 1.6155 1.6456.1504 1.9043.048 1.41 1.6103 1.0115 0.916 1.3443 1.183 1.3549 0.9847 1.8619 1.49 1.6167 1.7787 1.5841 1.8804 0.7314 rank(c) = 5 Berikut Modifikasi Soal Nomor () menjadi soal untuk dikerjakan dalam Scilab: Rank-Deficient Matrices In this exercise we consider how to use SCILAB to generate matrices with specified ranks. a In general, if A is an m x n matrix with rank r, then r <= min(m,n). Why? Explain. If the entries of A are random numbers, we would expect that r = min(m,n). Why? Explain. Check this out by generating random 7
6 x 6, 8 x 6, and 5 x 8 matrices and using the SCILAB command rank to compute their ranks. Whenever the rank of an m x n matrix equals min(m,n), we say that the matrix has full rank. Otherwise, we say that the matrix is rank deficient. Jika A adalah matriks m x n dengan rank r, maka r <= min(m,n) karena rank r adalah dimensi dari ruang baris sehingga rank r <= m, sedangkan dimensi ruang baris = dimensi ruang kolom sehingga rank r <= min(m,n). (Teorema) Jika entri dari matriks A adalah bilangan acak, kita dapat menduga bahwa r=min(m,n) karena antar baris tidak pernah merupakan kelipatan satu dengan yang lain. Generating random 6 x 6, 8 x 6, 5 x 8 matrices and compute their ranks using SCILAB command: A = rand(6,6) 0.8147 0.785 0.957 0.79 0.6787 0.7060 0.9058 0.5469 0.4854 0.9595 0.7577 0.0318 A = 0.170 0.9575 0.8003 0.6557 0.7431 0.769 0.9134 0.9649 0.1419 0.0357 0.39 0.046 0.634 0.1576 0.418 0.8491 0.6555 0.0971 0.0975 0.9706 0.9157 0.9340 0.171 0.835 rank(a) = 6 B = rand(8,6) 0.6948 0.1869 0.6551 0.7513 0.1493 0.1966 0.3171 0.4898 0.166 0.551 0.575 0.511 0.950 0.4456 0.1190 0.5060 0.8407 0.6160 B = 0.0344 0.6463 0.4984 0.6991 0.543 0.4733 0.4387 0.7094 0.9597 0.8909 0.8143 0.3517 0.3816 0.7547 0.3404 0.9593 0.435 0.8308 0.7655 0.760 0.5853 0.547 0.993 0.5853 0.795 0.6797 0.38 0.1386 0.3500 0.5497 rank(b) = 6 C = rand(5,8) 0.81 0.7317 0.7447 0.656 0.4868 0.5108 0.8116 0.550 0.0154 0.6477 0.1890 0.780 0.4359 0.8176 0.538 0.65 C = 0.0430 0.4509 0.6868 0.0811 0.4468 0.7948 0.3507 0.5870 0.1690 0.5470 0.1835 0.994 0.3063 0.6443 0.9390 0.077 0.6491 0.963 0.3685 0.7757 0.5085 0.3786 0.8759 0.301 rank(c) = 5 8
b SCILAB s rand and round commands can be used to generate random m x n matrices with integer entries in a given range [a,b]. This can be done with a command of the form For example, the command A = round((b-a)*rand(m,n))+a A = round(4*rand(6,8))+3 will generate a 6 x 8 matrix whose entries are random integers in the range from 3 to 7. Using the range [1,10], create random integer 10 x 7, 8 x 1, and 10 x 15 matrices and in each case check the rank of the matrix. Do these integer matrices all have full rank? Random integer 10 x 7 matrix in the range [1,10]: A1 = round(9*rand(10,7))+1 8 7 7 5 3 8 9 10 1 1 4 7 3 10 9 3 8 7 6 9 5 9 1 8 7 A1 = 7 8 7 3 9 8 8 5 5 10 4 5 8 7 5 10 6 6 9 5 4 7 4 10 8 7 10 7 6 10 10 3 1 8 3 3 rank(a1) = 7 This integer matrix has full rank because r = min(10,7) = 7. Random integer 8 x 1 matrix in the range [1,10]: A = round(9*rand(8,1))+1 9
9 7 8 9 4 5 4 5 4 3 5 8 6 5 5 6 1 8 4 4 6 3 3 9 5 9 8 3 8 6 5 6 9 10 8 6 A = 10 5 9 6 1 3 1 5 6 3 5 3 4 6 1 4 7 8 8 9 5 5 3 9 6 7 6 8 3 9 3 4 3 4 8 8 8 10 9 3 7 3 9 rank(a) = 8 This integer matrix has full rank because r = min(8,1) = 8. Random integer 10 x 15 matrix in the range [1,10]: A3 = round(9*rand(10,15))+1 9 7 4 6 9 3 5 4 5 7 4 9 7 10 8 10 8 7 6 6 3 4 6 5 7 4 9 7 8 6 7 8 8 7 3 3 5 3 4 7 8 6 8 5 8 6 5 5 6 5 10 7 3 6 5 3 6 9 7 3 4 6 10 1 A3 = 1 3 7 4 4 8 4 4 9 3 3 6 9 7 8 3 7 6 8 8 5 8 5 5 6 8 6 9 5 6 9 1 10 1 3 5 6 3 3 7 1 3 8 8 5 1 7 1 7 5 4 9 9 3 9 5 7 9 5 6 8 3 3 4 9 3 10 8 7 3 9 6 3 5 rank(a3) = 10 This integer matrix has full rank because r = min(10,15) = 10. 10
c Suppose that we want to use SCILAB to generate matrices with less than full rank. It is easy to generate matrices of rank 1. If x and y are nonzero vectors in R m and R n, respectively, then A = xy T will be an m x n matrix with rank 1. Why? Explain. Verify this in SCILAB by setting x = round(9*rand(8,1))+1, y = round(9*rand(6,1))+1 and using these vectors to construct an 8 x 6 matrix A. Check the rank of A with the SCILAB command rank. Jika x dan y adalah vektor-vektor taknol masing-masing di R m dan R n, maka A = xy T akan menjadi matriks m x n dengan rank 1 karena setiap baris pada matriks A (baris ke- sampai baris ke-m) merupakan kelipatan baris pertama, dapat dilihat dari bentuk eselon baris tereduksi dari matriks A. Construct an 8 x 6 matrix A: x = round(9*rand(8,1))+1 5 8 x = 3 5 8 8 y = round(9*rand(6,1))+1 5 y = 6 5 7 7 10 5 30 5 35 35 16 40 48 40 56 56 4 10 1 10 14 14 A = x y = 4 10 1 10 14 14 6 15 18 15 1 1 10 5 30 5 35 35 16 40 48 40 56 56 16 40 48 40 56 56 rank(a) = 1 11
d In general, rank(ab) <= min(rank(a),rank(b)) (1) (See Exercise 8 in Section 6.) If A and B are noninteger random matrices, the relation (1) should be an equality. Generate an 8 x 6 matrix A by setting X = rand(8,), Y = rand(6,), A = X*Y What would you expect the rank of A to be? Explain. Test the rank of A with SCILAB. X = rand(8,) 0.90 0.4897 0.4317 0.3395 0.0155 0.9516 X = 0.9841 0.903 0.167 0.057 0.106 0.7379 0.374 0.691 0.1981 0.48 Y = rand(6,) 0.5479 0.6663 0.947 0.5391 Y = 0.4177 0.6981 0.9831 0.6665 0.3015 0.1781 0.7011 0.180 0.4863 0.5393 0.4638 0.6134 0.175 0.674 0.467 0.5900 0.4173 0.6506 0.1906 0.3461 0.646 0.576 0.6708 0.6495 0.174 0.137 A = X Y = 1.154 1.439 1.0536 1.5808 0.4606 0.8077 0.167 0.1860 0.1066 0.1994 0.0598 0.139 0.5499 0.4979 0.5595 0.596 0.1635 0.1689 0.3834 0.496 0.3434 0.5455 0.160 0.955 0.3903 0.4147 0.3779 0.4766 0.1350 0.1930 Menurut dugaan saya, rank(a) = karena matriks X dan matriks Y adalah matriks yang berisi bilangan acak takbulat sehingga rank(x)= dan rank(y)=rank(y )=. Oleh karena itu, persamaan (1) berlaku sehingga rank(a)=rank(x*y )=min(rank(x),rank(y ))=min(,)=. Test the rank of A with SCILAB: 1
rank(a) = rank(x) = rank(y) = rank(y ) = e Use SCILAB to generate matrices A, B, and C such that (i) A is 8 x 8 with rank 3. (ii) B is 6 x 9 with rank 4. (iii) C is 10 x 7 with rank 5. A = rand(8,3)*(rand(8,3)) 0.083 0.6345 0.180 0.1190 0.688 0.053 0.804 0.8018 1.4601 0.7884 0.914 0.9057 1.593 1.0568 0.7963 0.853 0.966 1.0366 0.6461 0.858 1.046 0.6704 0.79 0.8407 A = 1.3117 0.639 0.804 0.808 1.3843 0.944 0.6347 0.6607 0.59 0.095 0.3044 0.1700 0.5791 0.411 0.904 0.815 0.9719 0.6895 0.5750 0.4090 1.3615 0.778 1.0466 1.0381 0.9671 0.5660 0.5787 0.4440 1.308 0.7514 0.883 0.861 1.4447 0.7678 0.889 0.770 1.683 1.085 0.9693 0.981 rank(a) = 3 B = rand(6,4)*(rand(9,4)) 0.7531 1.068 0.7318 0.6118 0.7794 0.718 0.3805 0.4644 0.6317 1.0753 0.7531 0.893 0.376 0.7485 0.6787 0.393 0.4070 0.613 B = 1.67 1.3797 1.1597 0.9838 1.857 1.655 0.6159 0.6135 0.8341 0.5357 0.4910 0.4839 0.393 0.5376 0.5356 0.396 0.165 0.316 1.1837 1.553 1.0144 1.0303 1.1841 1.431 0.7365 0.775 0.7685 1.464 1.7888 1.301 1.3010 1.5305 1.593 0.8581 0.833 0.9349 rank(b) = 4 C = rand(10,5)*(rand(7,5)) 1.6690 1.1011 1.149 1.5487 1.3678 1.5599 0.8984 1.6030 1.387 1.903 1.4143 1.40 1.7860 0.8303 1.4676 0.9909 1.1964 1.17 1.4084 1.5996 0.6791 1.737 1.5759 1.3959 1.8946 1.3098 1.707 0.8481 C = 1.569 1.18 1.1454 1.5636 1.335 1.5670 0.8530 1.6974 1.398 1.4 1.6564 1.5433 1.8807 1.044 0.9967 0.6554 0.7303 0.9195 0.8361 0.9369 0.4867.3488 1.6155 1.6456.1504 1.9043.048 1.41 1.6103 1.0115 0.916 1.3443 1.183 1.3549 0.9847 1.8619 1.49 1.6167 1.7787 1.5841 1.8804 0.7314 rank(c) = 5 13