Page 27 - MATLAB Recipes for Earth Sciences
P. 27

18                                            2 Introduction to MATLAB

               MATLAB provides standard arithmetic operators for  addition,  +, and
             subtraction, -. The  asterisk, *, denotes  matrix  multiplication involving  in-
            ner products between rows and columns. As an example, we multiply the
            matrix A with a new matrix B.

               B = [4 2 6 5; 7 8 5 6; 2 1 -8 -9; 3 1 2 3];
            The matrix  multiplication then is

               C = A * B
            which generates the output

               C =
                   63    46    22    28
                   61    43    81    78
                   46    34     7    11
                   66    61    38    33
            In linear algebra, matrices are used to keep track of the coefficients of  linear

            transformations. The multiplication of two matrices represents the combina-
            tion of two linear transformations to one single transformation. Matrix mul-
            tiplication is not communative, i.e., A*B and B*A yield different results in
            most cases. Accordingly, MATLAB provides  matrix divisions, right, /, and
            left, \, representing different transformations. Finally, the software allows
              power of matrices, ^, and  complex conjugate  transpose, ', i.e, turning rows
            into columns and columns into rows.
               In earth sciences, however, matrices are often simply used as two-di-
            mensional  arrays of numerical data instead of an array representing a linear
            transformation. Arithmetic operations on such arrays are done element-by-
            element. Whereas this does not make any difference in addition and subtrac-
            tion, the multiplicative operations are different. MATLAB uses a dot as part
            of the notation for these operations.
               For instance,  multiplying A and B  element-by-element is performed
            by typing
               C = A .* B

            which generates the output

               C =
                    8     8    18    35
                   63    24    -5    12
                    2     3   -24   -45
                   18     6     6    -6
   22   23   24   25   26   27   28   29   30   31   32