>> svd_demo ( 5, 5 ) 14-Sep-2006 11:55:25 SVD_DEMO (MATLAB version) Demonstrate the singular value decomposition (SVD) A real MxN matrix A can be factored as: A = U * S * V' where U = MxM orthogonal, S = MxN zero except for diagonal, V = NxN orthogonal. The diagonal of S contains only nonnegative numbers and these are arranged in descending order. Matrix row order M = 5 Matrix column order N = 5 We choose a "random" matrix A, with integral values between 0 and 10. The random number seed used to generate the matrix A is 1066921028 The matrix A: 1.000000 2.000000 8.000000 8.000000 0.000000 1.000000 3.000000 6.000000 8.000000 3.000000 1.000000 6.000000 3.000000 7.000000 3.000000 2.000000 6.000000 7.000000 3.000000 4.000000 6.000000 4.000000 6.000000 8.000000 7.000000 The orthogonal factor U: -0.4289 -0.7456 -0.0136 0.2627 -0.4369 -0.4396 -0.2795 -0.1375 -0.1349 0.8316 -0.3922 0.0910 0.1597 -0.8538 -0.2888 -0.4016 0.2935 0.7949 0.3397 0.0729 -0.5547 0.5211 -0.5688 0.2614 -0.1698 The diagonal factor S: 24.3114 0.0000 0.0000 0.0000 0.0000 0.0000 6.4187 0.0000 0.0000 0.0000 0.0000 0.0000 4.5695 0.0000 0.0000 0.0000 0.0000 0.0000 4.0760 0.0000 0.0000 0.0000 0.0000 0.0000 1.1237 The orthogonal factor V: -0.2218 0.4330 -0.3971 0.3734 -0.6828 -0.3767 0.3212 0.6592 -0.4705 -0.3147 -0.5506 -0.3409 0.3711 0.6570 0.1061 -0.6308 -0.3918 -0.4941 -0.4522 -0.0035 -0.3284 0.6631 -0.1611 0.0547 0.6508 The product U * S * V' 1.000000 2.000000 8.000000 8.000000 0.000000 1.000000 3.000000 6.000000 8.000000 3.000000 1.000000 6.000000 3.000000 7.000000 3.000000 2.000000 6.000000 7.000000 3.000000 4.000000 6.000000 4.000000 6.000000 8.000000 7.000000 Frobenius Norm of A, A_NORM = 25.903668 ABSOLUTE ERROR for A = U*S*V': Frobenius norm of difference A-U*S*V' = 0.000000 RELATIVE ERROR for A = U*S*V': Ratio of DIF_NORM / A_NORM = 0.000000 RANK_ONE_TEST: Compare A to the sum of R rank one matrices. R Absolute Relative Error Error 1 8.941862 0.345197 2 6.225513 0.240333 3 4.228039 0.163222 4 1.123710 0.043380 5 0.000000 0.000000 RANK_ONE_PRINT_TEST: Print the sums of R rank one matrices. Rank R = 1 2.312517 3.927571 5.740092 6.576760 3.424398 2.370394 4.025869 5.883754 6.741362 3.510103 2.114803 3.591775 5.249331 6.014466 3.131622 2.165653 3.678138 5.375549 6.159082 3.206921 2.991328 5.080462 7.425028 8.507290 4.429590 Rank R = 2 0.240184 2.390416 7.371553 8.451841 0.250963 1.593660 3.449726 6.495244 7.444163 2.320664 2.367729 3.779383 5.050213 5.785614 3.518937 2.981340 4.283174 4.733393 5.421035 4.456010 4.439542 6.154677 6.284910 7.196922 6.647290 Rank R = 3 0.264883 2.349422 7.348471 8.482568 0.260979 1.843270 3.035435 6.261971 7.754693 2.421895 2.077986 4.260287 5.320992 5.425155 3.401429 1.538837 6.677379 6.081483 3.626469 3.870993 5.471833 4.441324 5.320183 8.481158 7.065943 Rank R = 4 0.664786 1.845493 8.052103 7.998294 0.319522 1.638019 3.294076 5.900832 8.003247 2.391848 0.778441 5.897879 3.034437 6.998873 3.211187 2.055928 6.025778 6.991307 3.000285 3.946690 5.869712 3.939947 6.020251 7.999337 7.124189 Rank R = 5 1.000000 2.000000 8.000000 8.000000 0.000000 1.000000 3.000000 6.000000 8.000000 3.000000 1.000000 6.000000 3.000000 7.000000 3.000000 2.000000 6.000000 7.000000 3.000000 4.000000 6.000000 4.000000 6.000000 8.000000 7.000000 Original matrix A: 1.000000 2.000000 8.000000 8.000000 0.000000 1.000000 3.000000 6.000000 8.000000 3.000000 1.000000 6.000000 3.000000 7.000000 3.000000 2.000000 6.000000 7.000000 3.000000 4.000000 6.000000 4.000000 6.000000 8.000000 7.000000 The pseudoinverse of A: 0.2443 -0.5205 0.0931 -0.0588 0.2168 0.0594 -0.2443 0.2131 0.0759 -0.0300 0.0493 0.0704 -0.1479 0.1197 -0.0352 0.0303 0.0557 0.0830 -0.1314 0.0156 -0.3203 0.4617 -0.1696 0.0545 -0.0135 PSEUDO_PRODUCT_TEST The following relations MUST hold: A * A+ * A = A A+ * A * A+ = A+ ( A * A+ ) is MxM symmetric; ( A+ * A ) is NxN symmetric Here are the Frobenius norms of the errors in these relationships: A * A+ * A = A 0.000000 A+ * A * A+ = A+ 0.000000 ( A * A+ ) is MxM symmetric; 0.000000 ( A+ * A ) is NxN symmetric; 0.000000 In some cases, the matrix A * A+ may be interesting (if M <= N, then it MIGHT look like the identity.) 1.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 1.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 1.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 1.0000 0.0000 0.0000 0.0000 0.0000 0.0000 1.0000 In some cases, the matrix A+ * A+ may be interesting (if N <= M, then it MIGHT look like the identity.) 1.0000 0.0000 0.0000 0.0000 0.0000 0.0000 1.0000 0.0000 0.0000 0.0000 0.0000 0.0000 1.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 1.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 1.0000 PSEUDO_LINEAR_SOLVE_TEST Given: b = A * x1 so that b is in the range of A, solve A * x = b using the pseudoinverse: x2 = A+ * b. Norm of x1 = 13.379088 Norm of x2 = 13.379088 Norm of residual = 0.000000 Given: b = A' * x1 so that b is in the range of A', solve A' * x = b using the pseudoinverse: x2 = A+' * b. Norm of x1 = 15.394804 Norm of x2 = 15.394804 Norm of residual = 0.000000 SVD_DEMO: Normal end of execution. 14-Sep-2006 11:55:29 >>