Page 32 - Computational Colour Science Using MATLAB
P. 32

3





             A Short Introduction to MATLAB





             The key to using MATLAB successfully lies in the user’s ability to conceptualize
             data as square, rectangular, column and row matrices. Whereas most
             programming languages are based on ordinary algebra, whereby a symbol or
             name is used to represent a single numerical quantity, in MATLAB every name is
             assumed to be a matrix and the names can be manipulated via the rules of matrix
             arithmetic. MATLAB commands can be entered directly to the MATLAB
             Command Window at the >> prompt.
               In order to illustrate the use of MATLAB let us consider the problem defined
             by Equation (2.2) and examine how this problem could be solved using
             MATLAB. To enter a 2 2 matrix called M we can write


                  >>M = [1 1; 1 - 1];

             Note that the entries of M were entered within square brackets and that the rows
             were separated by a semi-colon. The final semi-colon at the end of the line is
             optional; if it is not present MATLAB will echo the values of M to the
             Command Window when the Return key is pressed. To enter a 2 1 column
             matrix p we would write


                  >>p = [6; 3];

             In order to solve Equation (2.2) we need to compute the inverse of matrix M and
             then multiply this by the matrix p. A major feature of MATLAB is that it
             provides many built-in, high-level functions and the function inv returns the
             inverse of a square matrix. Thus typing

                  >>inv(M)

             results in



             Computational Colour Science Using MATLAB. By Stephen Westland and Caterina Ripamonti.
             & 2004 John Wiley & Sons, Ltd: ISBN 0 470 84562 7
   27   28   29   30   31   32   33   34   35   36   37