Page 15 - Computational Colour Science Using MATLAB
P. 15

2                           INTRODUCTION

               1.2 Why base this book upon MATLAB?

               This book describes algorithms and mathematical procedures in colour science
               and illustrates these procedures using the numerical software tool called
               MATLAB. MATLAB provides several features that make it suitable for the
               implementation of algorithms in general, and colour-science algorithms in
               particular, and results in code that is easily understandable by the reader with
               relatively little experience of writing software. These features include the use of
               operations upon vectors and matrices to enable compact code that avoids the
               excessive use of looping procedures, the provision of a massive library of
               functions that the MATLAB programmer can call upon and the ease of use of
               graphics functions to enable the user to easily and effectively visualise complex
               data structures.
                 Most computer languages are very dependent upon a variety of ‘looping’
               procedures to execute summations or to implement iterative techniques whereas
               MATLAB enables these types of operations to be performed with a fraction of
               the code. For example, if we have two variables x and y, each consisting of five
               entries, and we wish to compute the product of the corresponding entries and
               then sum the results to yield a single number, we might write code that in BASIC
               looks like the following:


                    sum = 0
                    FOR i=1 TO 5
                    sum = sum + x(i)*y(i)
                    NEXT i

               In MATLAB the four lines of BASIC code shown could be replaced by the single
               line


                    sum = x*y;

               Expressed in terms of linear algebra MATLAB will perform the inner product of
               the vectors x and y automatically. In the MATLAB environment it is not
               necessary to specify how many entries the variables contain, so long as the
               dimensions of these variables define a valid matrix operation. A variable in
               MATLAB can represent a single number, a vector or a whole matrix. The
               operation given, for example, by

                    y = 2*x

               will assign to y twice the value of x if x defines a single number, but twice the
               value of every element in x if x is a vector or a matrix. The compact nature of
               MATLAB code allows complex and sophisticated algorithms to be explained
   10   11   12   13   14   15   16   17   18   19   20