Page 33 - Numerical Analysis Using MATLAB and Excel
P. 33

Chapter 1  Introduction to MATLAB


                    6
                   11
               We will now define Matrix Multiplication and Element−by−Element multiplication.

               1. Matrix Multiplication (multiplication of row by column vectors)

                   Let
                                                 A =   [  a    a    a    …   a ]  1  2  3  n
                   and
                                                  B =  [  b    b    b    …   b ]  1  2  3  n  '

                   be two vectors. We observe that   is defined as a row vector whereas   is defined as a column
                                                                                      B
                                                  A
                   vector, as indicated by the transpose operator (′). Here, multiplication of the row vector   by
                                                                                                        A
                   the column vector B , is performed with the matrix multiplication operator (*). Then,

                               A*B =    [  a b +  a b +  a b +  … +  a b ]  n n  =  sin gle value      (B.15)
                                                       3
                                                  2
                                          1
                                                2
                                            1
                                                         3
                   For example, if
                                                   A =   [  1   2   3   4   5 ]
                   and
                                                                         ]
                                                                –
                                                  B =   – [  2   6    3   8   7 '
                   the matrix multiplication A*B  produces the single value 68, that is,
                                                   )
                                    A∗ B =   1 ×  – (  2 +  2 ×  6 + 3 ×  – (  3 + 4 × 8 +  5 ×  7 =  68
                                                                    )
                   and this is verified with the MATLAB script


                   A=[1   2    3   4   5]; B=[ −2   6  −3   8   7]'; A*B  % Observe transpose operator (‘) in B
                   ans =

                   68
                   Now, let us suppose that both   and   are row vectors, and we attempt to perform a row−by−
                                                       B
                                                A
                   row multiplication with the following MATLAB statements.
                   A=[1  2   3  4  5]; B=[−2  6  −3  8  7]; A*B   % No transpose operator (‘) here
                   When these statements are executed, MATLAB displays the following message:
                   ??? Error using ==> *

                   Inner matrix dimensions must agree.
                   Here, because we have used the matrix multiplication operator (*) in A*B, MATLAB expects





               1−20                             Numerical Analysis Using MATLAB® and Excel®, Third Edition
                                                                             Copyright © Orchard Publications
   28   29   30   31   32   33   34   35   36   37   38