Page 31 - Applied Numerical Methods Using MATLAB
P. 31

20    MATLAB USAGE AND COMPUTATIONAL ERRORS
              2. If matrix A is square, symmetric (Hermitian), and positive definite, then
                MATLAB finds the solution by using Cholesky factorization (Section 2.4.2).
              3. If matrix A is square and has no special feature, then MATLAB finds the
                solution by using LU decomposition (Section 2.4.1).
              4. If matrix A is rectangular, then MATLAB finds a solution by using QR
                factorization (Section 2.4.2). In case A is rectangular and of full rank with
                rank(A) = min(M,N), it will be the LS (least-squares) solution [Eq. (2.1.10)]
                for M>N (overdetermined case) and one of the many solutions that is not
                always the same as the minimum-norm solution [Eq. (2.1.7)] for M<N
                (underdetermined case). But for the case when A is rectangular and has
                rank deficiency, what MATLAB gives us may be useless. Therefore, you
                must pay attention to the warning message about rank deficiency, which
                might tell you not to count on the dead-end solution made by the backslash
                (\) operator. To find an alternative in the case of rank deficiency, you
                had better resort to singular value decomposition (SVD). See Problem 2.8
                for details.

           For the moment, let us continue to try more operations on matrices.
           >>A1./A2 %termwise right division
             ans =  1     1     1
                   -2    Inf    2
           >>A1.\A2 %termwise left division
             ans =  1     1     1
                   -0.5   0     0.5
           >>format rat, B^-1 %represent the numbers (of B −1 ) in fractional form
             ans =  0   -1/3
                   -1/2  -1/6
           >>inv(B) %inverse matrix, equivalently
             ans =  0    -1/3
                   -1/2  -1/6
           >>B.^-1 %termwise inversion(reciprocal of each element)
             ans =  1    -1/2
                   -1/3   Inf
           >>B^2 %square of B, i.e., B 2  = B ∗ B
             ans =  7    -2
                   -3     6
           >>B.^2 %termwise square(square of each element)
                              2
                      2
             ans =  1(b )  4(b )
                      11
                              12
                      2
                              2
                    9(b )  0(b )
                      21
                              22
           >>2.^B %2 to the power of each number in B
             ans =  2 (2 b 11 )  1/4(2 b 12 )
                    1/8(2 b 21 )  1 (2 b 22 )
           >>A1.^A2 %element of A1 to the power of each element in A2
             ans =  -1 (A 1 (1, 1) A 2 (1,1) )  4(A 1 (1, 2) A 2 (1,2) )  27(A 1 (1, 3) A 2 (1,3) )
                   1/16(A 1 (2, 1) A 2 (2,1) )  1(A 1 (2, 2) A 2 (2,2) )  2(A 1 (2, 3) A 2 (2,3) )
           >>format short, exp(B) %elements of e B  with 4 digits below the dp
             ans = 2.7183(e b 11 )  0.1353(e b 12 )
                   0.0498(e b 21 )  1.0000(e b 22 )
              There are more useful MATLAB commands worthwhile to learn by heart.
   26   27   28   29   30   31   32   33   34   35   36