Page 27 - Applied Numerical Methods Using MATLAB
P. 27

16    MATLAB USAGE AND COMPUTATIONAL ERRORS
           which makes

            t = [0.0 0.1 0.2 ... 1.9 2.0]

               (Q6) What if we omit the increment between the left/right boundary numbers?
               (A6) By default, the increment is 1.
                   >>t = 0:2
                     t=012

               (Q7) What if the right boundary number is smaller/greater than the left boundary
                   number with a positive/negative increment?
               (A7) It yields an empty matrix, which is useless.
                   >>t = 0:-2
                     t = Empty matrix: 1-by-0

               (Q8) If we define just some elements of a vector not fully, but sporadically, will we
                   have a row vector or a column vector and how will it be filled in between?
               (A8) We will have a row vector filled with zeros between the defined elements.

                   >>D(2) = 2; D(4) = 3
                     D = 0   2   0   3

               (Q9) How do we make a column vector in the same style?
               (A9) We must initialize it as a (zero-filled) row vector, prior to giving it a value.

                   >>D = zeros(4,1); D(2) = 2; D(4) = 3
                     D=0
                           2
                           0
                           3

              (Q10) What happens if the specified element index of an array exceeds the defined
                   range?
              (A10) It is rejected. MATLAB does not accept nonpositive or noninteger indices.

                   >>D(5)
                      ??? Index exceeds matrix dimensions.
                   >>D(0) = 1;
                      ??? Index into matrix is negative or zero.
                   >>D(1.2)
                      ??? Subscript indices must either be real positive
                         integers ..

              (Q11) How do we know the size (the numbers of rows/columns) of an already-
                   defined array?
   22   23   24   25   26   27   28   29   30   31   32