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

Chapter 4  Matrices and Determinants


                                                           2   3 5   2   3
                                                  detA =   1  0   1 1    0
                                                           2   1  0 2 1
                or
                                                  )
                                                              )
                                                         1
                                  detA=  (  2 ×  0 × 0 +  (  3 × × 1 +  (  5 × 1 × 1 )
                                                                            )
                                                                )
                                                    )
                                          –  (  2 ×  0 × 5 –  (  1 ×  1 ×  2 –  (  0 ×  1 ×  3 =  11 –  2 =  9
                Likewise,
                                                              –
                                                           23 4      23
                                                                 –
                                                                       –
                                                   detB =  10 2 1 –     2
                                                                 –
                                                                 –
                                                              –
                                                           05 6 2 –     6
                or
                                                                     )
                                                   )
                                                          )
                                                              ]
                         detB=  [  2 × ×  – (  6 ]  )  +  – ( [  3 ×  – (  2 × 0 +  – ( [  4 ×  1 ×  – (  5 ]  )
                                     0
                                                                       )
                                                           )
                                                                ]
                                                     )
                                                                          1
                                –  [  0 ×  0 ×  – (  4 ]  )  –  – ( [  5 ×  – (  2 ×  2 –  – ( [  6 × ×  – (  3 ]  )  =  20 – 38 =  – 18
                Check with MATLAB:
                A=[2   3   5;  1   0   1;  2   1   0]; det(A)  % Define matrix A and compute detA
                ans =
                     9
                B=[2   −3   −4;  1   0   −2;  0   −5   −6]; det(B)  % Define matrix B and compute detB
                ans =
                   -18
                The MATLAB user−defined function file below can be used to compute the determinant of a
                3 ×  3  matrix.
                % This file computes the determinant of a 3x3 matrix
                % It must be saved as function (user defined) file
                % det3x3.m in the current Work Directory. Make sure
                % that his directory is added to MATLAB's search
                % path accessed from the Editor Window as File>Set Path>
                % Add Folder. It is highly recommended that this
                % function file is created in MATLAB's Editor Window.
                %
                function y=det3x3(A);
                y=A(1,1)*A(2,2)*A(3,3)+A(1,2)*A(2,3)*A(3,1)+A(1,3)*A(2,1)*A(3,2)...
                    −A(3,1)*A(2,2)*A(1,3)−A(3,2)*A(2,3)*A(1,1)−A(3,3)*A(2,1)*A(1,2);
                %
                % To run this program, define the 3x3 matrix in
                % MATLAB's Command Window as A=[....] and then
                % type det3x3(A) at the command prompt.







               4−12                             Numerical Analysis Using MATLAB® and Excel®, Third Edition

                                                                             Copyright © Orchard Publications
   125   126   127   128   129   130   131   132   133   134   135