Page 33 - Computational Colour Science Using MATLAB
P. 33

20               A SHORT INTRODUCTION TO MATLAB

                    ans =
                    0.5000      0.5000
                    0.5000     -0.5000

               and the inverse of M is computed and displayed in the Command Window. At
               any time it is possible to type the command whos and this displays a list of the
               current variables and their dimensions; thus


                    >>whos
                    Name   Size          Bytes       Class
                    M      2 2           32          double array
                    ans    2 2           32          double array
                    p      2 1           16          double array
                    Grand total is 10 elements using 80 bytes

               Note that since we did not assign the output of the inv command to any variable
               it was automatically assigned to the variable ans.
                 We can now compute the solution to Equation (2.2) easily by typing

                    >>a = inv(M)*p
                    a=
                    4.5000
                    1.5000

               which gives, of course, the same result as that achieved by the substitution
               method that was briefly described in Chapter 2.
                 In the following sections the basic properties of MATLAB are briefly
               introduced and some of its useful functions are described.





               3.1 Matrix operations

               Matrices may be added, subtracted and multiplied using the conventional
               symbols +,   and  . Matrices may also be easily augmented thus

                    >>M = [1 1; 1 -1];
                    >>M = [M; M]
                    M=
                      1     1
                      1    -1
                      1     1
                      1    -1
   28   29   30   31   32   33   34   35   36   37   38