Praktikum Metode Komputasi (Vector Spaces)
Vina Apriliani
January 17, 2016
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 (2 digit terakhir NRP modulo jumlah soal di Latihan) yaitu Soal Nomor (2):
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.
Answer:
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) A = 0.8147 0.2785 0.9572 0.7922 0.6787 0.7060 0.9058 0.5469 0.4854 0.9595 0.7577 0.0318 0.1270 0.9575 0.8003 0.6557 0.7431 0.2769 0.9134 0.9649 0.1419 0.0357 0.3922 0.0462 0.6324 0.1576 0.4218 0.8491 0.6555 0.0971 0.0975 0.9706 0.9157 0.9340 0.1712 0.8235
rank(A) = 6 B = rand(8,6) B = 0.6948 0.1869 0.6551 0.7513 0.1493 0.1966 0.3171 0.4898 0.1626 0.2551 0.2575 0.2511 0.9502 0.4456 0.1190 0.5060 0.8407 0.6160 0.0344 0.6463 0.4984 0.6991 0.2543 0.4733 0.4387 0.7094 0.9597 0.8909 0.8143 0.3517 0.3816 0.7547 0.3404 0.9593 0.2435 0.8308 0.7655 0.2760 0.5853 0.5472 0.9293 0.5853 0.7952 0.6797 0.2238 0.1386 0.3500 0.5497 rank(B) = 6 C = rand(5,8) C = 0.8212 0.7317 0.7447 0.6256 0.4868 0.5108 0.8116 0.5502 0.0154 0.6477 0.1890 0.7802 0.4359 0.8176 0.5328 0.6225 0.0430 0.4509 0.6868 0.0811 0.4468 0.7948 0.3507 0.5870 0.1690 0.5470 0.1835 0.9294 0.3063 0.6443 0.9390 0.2077 0.6491 0.2963 0.3685 0.7757 0.5085 0.3786 0.8759 0.3012 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
A = round((b-a)*rand(m,n))+a For example, the command
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 12, and 10 x 15 matrices and in each case check the rank of the matrix. Do these integer matrices all have full rank?
Answer:
Random integer 10 x 7 matrix in the range [1,10]: A1 = round(9*rand(10,7))+1
A1 = 8 2 7 7 5 3 8 9 10 1 1 4 7 3 2 10 9 3 8 7 6 9 5 9 1 8 2 7 7 8 7 2 3 2 9 2 2 8 8 5 5 10 4 5 8 7 5 10 6 6 9 5 4 7 4 2 10 8 7 10 7 6 2 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 12 matrix in the range [1,10]:
A2 = round(9*rand(8,12))+1 A2 = 9 7 8 9 4 5 2 2 2 4 5 4 3 5 8 2 6 2 5 5 2 6 1 2 8 4 4 6 2 3 2 3 9 5 9 8 3 8 6 5 6 9 10 8 6 2 10 5 9 6 2 1 3 2 1 5 6 3 5 3 4 6 1 4 7 8 8 9 2 2 5 5 3 9 6 2 7 6 8 3 9 3 4 2 3 4 8 8 8 10 9 3 7 3 9 2 rank(A2) = 8
This integer matrix has full rank because r = min(8,12) = 8. Random integer 10 x 15 matrix in the range [1,10]:
A3 = 9 7 4 6 9 3 5 4 5 7 4 9 7 10 8 10 8 7 6 6 3 2 4 6 5 7 4 9 7 8 6 7 8 8 7 3 3 5 3 4 2 7 8 6 8 2 5 2 8 6 5 5 6 5 10 7 3 6 5 2 3 6 9 7 3 4 6 2 10 1 2 1 3 2 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 2 7 1 7 5 4 9 9 3 9 5 2 7 9 5 6 8 3 3 4 9 3 10 2 8 7 3 9 6 3 2 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 Rmand Rn, respectively, then A = xyT 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.
Answer:
Jika x dan y adalah vektor-vektor taknol masing-masing di Rm dan Rn, maka A = xyT akan menjadi matriks m x n dengan rank 1 karena setiap baris pada matriks A (baris ke-2 sampai baris ke-m) merupakan kelipatan baris pertama, dapat dilihat dari bentuk eselon baris tereduksi dari ma-triks A.
Construct an 8 x 6 matrix A: x = round(9*rand(8,1))+1
x = 5 8 2 2 3 5 8 8 y = round(9*rand(6,1))+1 y = 2 5 6 5 7 7 A = x ∗ y0= 10 25 30 25 35 35 16 40 48 40 56 56 4 10 12 10 14 14 4 10 12 10 14 14 6 15 18 15 21 21 10 25 30 25 35 35 16 40 48 40 56 56 16 40 48 40 56 56 rank(A) = 1 d In general, rank(AB) <= min(rank(A),rank(B)) (1)
(See Exercise 28 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,2), Y = rand(6,2), A = X*Y’
What would you expect the rank of A to be? Explain. Test the rank of A with MATLAB.
Answer: X = rand(8,2)
X = 0.2920 0.4897 0.4317 0.3395 0.0155 0.9516 0.9841 0.9203 0.1672 0.0527 0.1062 0.7379 0.3724 0.2691 0.1981 0.4228 Y = rand(6,2) Y = 0.5479 0.6663 0.9427 0.5391 0.4177 0.6981 0.9831 0.6665 0.3015 0.1781 0.7011 0.1280 A = X ∗ Y0 = 0.4863 0.5393 0.4638 0.6134 0.1752 0.2674 0.4627 0.5900 0.4173 0.6506 0.1906 0.3461 0.6426 0.5276 0.6708 0.6495 0.1742 0.1327 1.1524 1.4239 1.0536 1.5808 0.4606 0.8077 0.1267 0.1860 0.1066 0.1994 0.0598 0.1239 0.5499 0.4979 0.5595 0.5962 0.1635 0.1689 0.3834 0.4962 0.3434 0.5455 0.1602 0.2955 0.3903 0.4147 0.3779 0.4766 0.1350 0.1930 Menurut dugaan saya, rank(A) = 2 karena matriks X dan matriks Y adalah matriks yang berisi bilangan acak takbulat sehingga rank(X)=2 dan rank(Y)=rank(Y’)=2. Oleh karena itu, persamaan (1) berlaku se-hingga rank(A)=rank(X*Y’)=min(rank(X),rank(Y’))=min(2,2)=2. Test the rank of A with MATLAB:
rank(A) = 2 rank(X) = 2
rank(Y) = rank(Y’) = 2
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. Answer:
A = rand(8,3)*(rand(8,3))’ A = 0.2083 0.6345 0.1280 0.1190 0.6288 0.2053 0.8042 0.8018 1.4601 0.7884 0.9142 0.9057 1.5932 1.0568 0.7963 0.8253 0.9626 1.0366 0.6461 0.8528 1.2046 0.6704 0.7922 0.8407 1.3117 0.6392 0.8204 0.8082 1.3843 0.9442 0.6347 0.6607 0.5292 0.0952 0.3044 0.1700 0.5791 0.4121 0.2904 0.2815 0.9719 0.6895 0.5750 0.4090 1.3615 0.7782 1.0466 1.0381 0.9671 0.5660 0.5787 0.4440 1.2308 0.7514 0.8283 0.8261 1.4447 0.7678 0.8829 0.7702 1.6823 1.0825 0.9693 0.9812 rank(A) = 3 B = rand(6,4)*(rand(9,4))’ B = 0.7531 1.0628 0.7318 0.6118 0.7794 0.7128 0.3805 0.4644 0.6317 1.0753 0.7531 0.8293 0.3726 0.7485 0.6787 0.3932 0.4070 0.6123 1.2672 1.3797 1.1597 0.9838 1.2857 1.2655 0.6159 0.6135 0.8341 0.5357 0.4910 0.4839 0.3932 0.5376 0.5356 0.2396 0.2165 0.3162 1.1837 1.5253 1.0144 1.0303 1.1841 1.2431 0.7365 0.7275 0.7685 1.4642 1.7888 1.3021 1.3010 1.5305 1.5932 0.8581 0.8233 0.9349 rank(B) = 4 C = rand(10,5)*(rand(7,5))’ C = 1.6690 1.1011 1.1492 1.5487 1.3678 1.5599 0.8984 1.6030 1.3287 1.2903 1.4143 1.4220 1.7860 0.8303 1.4676 0.9909 1.1964 1.2127 1.4084 1.5996 0.6791 1.7237 1.5759 1.3959 1.8946 1.3098 1.7207 0.8481 1.5692 1.1282 1.1454 1.5636 1.3235 1.5670 0.8530 1.6974 1.2398 1.2224 1.6564 1.5433 1.8807 1.0424 0.9967 0.6554 0.7303 0.9195 0.8361 0.9369 0.4867 2.3488 1.6155 1.6456 2.1504 1.9043 2.2048 1.2412 1.6103 1.0115 0.9126 1.3443 1.1823 1.3549 0.9847 1.8619 1.4922 1.6167 1.7787 1.5841 1.8804 0.7314 rank(C) = 5
Berikut Modifikasi Soal Nomor (2) 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
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.
Answer:
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) A = 0.8147 0.2785 0.9572 0.7922 0.6787 0.7060 0.9058 0.5469 0.4854 0.9595 0.7577 0.0318 0.1270 0.9575 0.8003 0.6557 0.7431 0.2769 0.9134 0.9649 0.1419 0.0357 0.3922 0.0462 0.6324 0.1576 0.4218 0.8491 0.6555 0.0971 0.0975 0.9706 0.9157 0.9340 0.1712 0.8235 rank(A) = 6 B = rand(8,6) B = 0.6948 0.1869 0.6551 0.7513 0.1493 0.1966 0.3171 0.4898 0.1626 0.2551 0.2575 0.2511 0.9502 0.4456 0.1190 0.5060 0.8407 0.6160 0.0344 0.6463 0.4984 0.6991 0.2543 0.4733 0.4387 0.7094 0.9597 0.8909 0.8143 0.3517 0.3816 0.7547 0.3404 0.9593 0.2435 0.8308 0.7655 0.2760 0.5853 0.5472 0.9293 0.5853 0.7952 0.6797 0.2238 0.1386 0.3500 0.5497 rank(B) = 6 C = rand(5,8) C = 0.8212 0.7317 0.7447 0.6256 0.4868 0.5108 0.8116 0.5502 0.0154 0.6477 0.1890 0.7802 0.4359 0.8176 0.5328 0.6225 0.0430 0.4509 0.6868 0.0811 0.4468 0.7948 0.3507 0.5870 0.1690 0.5470 0.1835 0.9294 0.3063 0.6443 0.9390 0.2077 0.6491 0.2963 0.3685 0.7757 0.5085 0.3786 0.8759 0.3012 rank(C) = 5
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
A = round((b-a)*rand(m,n))+a For example, the command
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 12, and 10 x 15 matrices and in each case check the rank of the matrix. Do these integer matrices all have full rank?
Answer:
Random integer 10 x 7 matrix in the range [1,10]: A1 = round(9*rand(10,7))+1 A1 = 8 2 7 7 5 3 8 9 10 1 1 4 7 3 2 10 9 3 8 7 6 9 5 9 1 8 2 7 7 8 7 2 3 2 9 2 2 8 8 5 5 10 4 5 8 7 5 10 6 6 9 5 4 7 4 2 10 8 7 10 7 6 2 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 12 matrix in the range [1,10]:
A2 = 9 7 8 9 4 5 2 2 2 4 5 4 3 5 8 2 6 2 5 5 2 6 1 2 8 4 4 6 2 3 2 3 9 5 9 8 3 8 6 5 6 9 10 8 6 2 10 5 9 6 2 1 3 2 1 5 6 3 5 3 4 6 1 4 7 8 8 9 2 2 5 5 3 9 6 2 7 6 8 3 9 3 4 2 3 4 8 8 8 10 9 3 7 3 9 2 rank(A2) = 8
This integer matrix has full rank because r = min(8,12) = 8. Random integer 10 x 15 matrix in the range [1,10]:
A3 = round(9*rand(10,15))+1 A3 = 9 7 4 6 9 3 5 4 5 7 4 9 7 10 8 10 8 7 6 6 3 2 4 6 5 7 4 9 7 8 6 7 8 8 7 3 3 5 3 4 2 7 8 6 8 2 5 2 8 6 5 5 6 5 10 7 3 6 5 2 3 6 9 7 3 4 6 2 10 1 2 1 3 2 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 2 7 1 7 5 4 9 9 3 9 5 2 7 9 5 6 8 3 3 4 9 3 10 2 8 7 3 9 6 3 2 5 rank(A3) = 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 Rmand Rn, respectively, then A = xyT 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.
Answer:
Jika x dan y adalah vektor-vektor taknol masing-masing di Rm dan Rn,
maka A = xyT akan menjadi matriks m x n dengan rank 1 karena setiap
baris pada matriks A (baris ke-2 sampai baris ke-m) merupakan kelipatan baris pertama, dapat dilihat dari bentuk eselon baris tereduksi dari ma-triks A. Construct an 8 x 6 matrix A: x = round(9*rand(8,1))+1 x = 5 8 2 2 3 5 8 8 y = round(9*rand(6,1))+1 y = 2 5 6 5 7 7 A = x ∗ y0= 10 25 30 25 35 35 16 40 48 40 56 56 4 10 12 10 14 14 4 10 12 10 14 14 6 15 18 15 21 21 10 25 30 25 35 35 16 40 48 40 56 56 16 40 48 40 56 56 rank(A) = 1
d In general,
rank(AB) <= min(rank(A),rank(B)) (1)
(See Exercise 28 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,2), Y = rand(6,2), A = X*Y’
What would you expect the rank of A to be? Explain. Test the rank of A with SCILAB. Answer: X = rand(8,2) X = 0.2920 0.4897 0.4317 0.3395 0.0155 0.9516 0.9841 0.9203 0.1672 0.0527 0.1062 0.7379 0.3724 0.2691 0.1981 0.4228 Y = rand(6,2) Y = 0.5479 0.6663 0.9427 0.5391 0.4177 0.6981 0.9831 0.6665 0.3015 0.1781 0.7011 0.1280 A = X ∗ Y0 = 0.4863 0.5393 0.4638 0.6134 0.1752 0.2674 0.4627 0.5900 0.4173 0.6506 0.1906 0.3461 0.6426 0.5276 0.6708 0.6495 0.1742 0.1327 1.1524 1.4239 1.0536 1.5808 0.4606 0.8077 0.1267 0.1860 0.1066 0.1994 0.0598 0.1239 0.5499 0.4979 0.5595 0.5962 0.1635 0.1689 0.3834 0.4962 0.3434 0.5455 0.1602 0.2955 0.3903 0.4147 0.3779 0.4766 0.1350 0.1930 Menurut dugaan saya, rank(A) = 2 karena matriks X dan matriks Y adalah matriks yang berisi bilangan acak takbulat sehingga rank(X)=2 dan rank(Y)=rank(Y’)=2. Oleh karena itu, persamaan (1) berlaku se-hingga rank(A)=rank(X*Y’)=min(rank(X),rank(Y’))=min(2,2)=2.
rank(A) = 2 rank(X) = 2
rank(Y) = rank(Y’) = 2
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. Answer: A = rand(8,3)*(rand(8,3))’ A = 0.2083 0.6345 0.1280 0.1190 0.6288 0.2053 0.8042 0.8018 1.4601 0.7884 0.9142 0.9057 1.5932 1.0568 0.7963 0.8253 0.9626 1.0366 0.6461 0.8528 1.2046 0.6704 0.7922 0.8407 1.3117 0.6392 0.8204 0.8082 1.3843 0.9442 0.6347 0.6607 0.5292 0.0952 0.3044 0.1700 0.5791 0.4121 0.2904 0.2815 0.9719 0.6895 0.5750 0.4090 1.3615 0.7782 1.0466 1.0381 0.9671 0.5660 0.5787 0.4440 1.2308 0.7514 0.8283 0.8261 1.4447 0.7678 0.8829 0.7702 1.6823 1.0825 0.9693 0.9812 rank(A) = 3 B = rand(6,4)*(rand(9,4))’ B = 0.7531 1.0628 0.7318 0.6118 0.7794 0.7128 0.3805 0.4644 0.6317 1.0753 0.7531 0.8293 0.3726 0.7485 0.6787 0.3932 0.4070 0.6123 1.2672 1.3797 1.1597 0.9838 1.2857 1.2655 0.6159 0.6135 0.8341 0.5357 0.4910 0.4839 0.3932 0.5376 0.5356 0.2396 0.2165 0.3162 1.1837 1.5253 1.0144 1.0303 1.1841 1.2431 0.7365 0.7275 0.7685 1.4642 1.7888 1.3021 1.3010 1.5305 1.5932 0.8581 0.8233 0.9349 rank(B) = 4 C = rand(10,5)*(rand(7,5))’ C = 1.6690 1.1011 1.1492 1.5487 1.3678 1.5599 0.8984 1.6030 1.3287 1.2903 1.4143 1.4220 1.7860 0.8303 1.4676 0.9909 1.1964 1.2127 1.4084 1.5996 0.6791 1.7237 1.5759 1.3959 1.8946 1.3098 1.7207 0.8481 1.5692 1.1282 1.1454 1.5636 1.3235 1.5670 0.8530 1.6974 1.2398 1.2224 1.6564 1.5433 1.8807 1.0424 0.9967 0.6554 0.7303 0.9195 0.8361 0.9369 0.4867 2.3488 1.6155 1.6456 2.1504 1.9043 2.2048 1.2412 1.6103 1.0115 0.9126 1.3443 1.1823 1.3549 0.9847 1.8619 1.4922 1.6167 1.7787 1.5841 1.8804 0.7314 rank(C) = 5