home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / RLaB 1.15c / help / MATRICES < prev    next >
Encoding:
Text File  |  1994-07-30  |  4.6 KB  |  183 lines  |  [TEXT/RLAB]

  1.  but ONLY at the semicolon, and the semicolon
  2.     cannot be left out.
  3.  
  4.     Matrices can be composed of other scalars, vectors and
  5.     matrices...
  6.  
  7.     > s = 1;
  8.     > v = 4:6;
  9.     > m = [s, 2, 3; v]
  10.      m =
  11.      matrix columns 1 thru 3
  12.                1           2           3
  13.                4           5           6
  14.  
  15.     To extract, or assign to matrix elements:
  16.  
  17.     > m[1;1]
  18.                1
  19.     > m[1;1] = 100
  20.      m =
  21.      matrix columns 1 thru 3
  22.              100           2           3
  23.                4           5           6
  24.  
  25.     When assigning values to matrix elements index checking is
  26.     automatically performed. When an index value exceeds the
  27.     dimension of the matrix, the size of the matrix is
  28.     automatically extended to accommodate the new value.
  29.  
  30.     clear(m);
  31.     m[1;1] = 10;
  32.  
  33.     Then the variable is automatically converted to a matrix
  34.     object, and sized appropriately.
  35.  
  36.     The following works, but is very inefficient:
  37.  
  38.     for(i in 1:4) {
  39.       for(j in 1:4) {
  40.         a[i;j] = i+j;
  41.       }
  42.     }
  43.  
  44.     since we are constantly extending the size of the matrix.
  45.     However, it is very convenient.
  46.  
  47.     Vectors can be used as matrix index values:
  48.  
  49.     > a=[1,2,3,4;5,6,7,8;9,10,11,12]
  50.      a =
  51.      matrix columns 1 thru 4
  52.                1           2           3           4
  53.                5           6           7           8
  54.                9          10          11          12
  55.  
  56.     > a[2,3;2,3]
  57.      matrix columns 1 thru 2
  58.                6           7
  59.               10          11
  60.  
  61.     > a[2;]
  62.      matrix columns 1 thru 4
  63.                5           6           7           8
  64.  
  65.     > a[;2]
  66.      matrix columns 1 thru 1
  67.                2
  68.                6
  69.               10
  70.     
  71.     > a[;2] = 200,600,1000
  72.      a =
  73.      matrix columns 1 thru 4
  74.                1         200           3           4
  75.                5         600           7           8
  76.                9       1e+03          11          12
  77.  
  78.     Matrix properties can be obtained from functions such as:
  79.     class(), type(), and size(). Additionally they can be obtained
  80.     by using the LIST-like syntax to reference the data:
  81.  
  82.     > m=[1,2,3;4,5,6;7,8,9;10,11,12]
  83.      m =
  84.      matrix columns 1 thru 3
  85.                1           2           3
  86.                4           5           6
  87.                7           8           9
  88.               10          11          12
  89.     > m.class
  90.     num
  91.     > m.type
  92.     real
  93.     > m.nr
  94.             4
  95.     > m.nc
  96.             3
  97.     > m.n
  98.            12
  99.     > show ( m )
  100.        name:      m     
  101.        class:     num   
  102.        type:      real  
  103.          nr:      4     
  104.          nc:      3     
  105.  
  106.     The show() function shows all of the available entity
  107.     information as once.
  108.  
  109.     Matrices can also be used like single dimension arrays. Any
  110.     matrix can be indexed with a single dimension `m[i]'. The
  111.     effect is to walk the matrix in a column fashion, thus:
  112.  
  113.     > m
  114.      m =
  115.      matrix columns 1 thru 3
  116.                1           2           3
  117.                4           5           6
  118.                7           8           9
  119.               10          11          12
  120.     > m[1]
  121.                1
  122.     > m[2]
  123.                4
  124.     > m[3]
  125.                7
  126.  
  127.     Matrices can also be forced into the shape of a column vector
  128.     with the `[:]' operator.
  129.  
  130.     > m[:]
  131.      matrix columns 1 thru 1
  132.             1  
  133.             4  
  134.             7  
  135.            10  
  136.             2  
  137.             5  
  138.             8  
  139.            11  
  140.             3  
  141.             6  
  142.             9  
  143.            12  
  144.  
  145.     ================================================================
  146.  
  147.      String Matrices:
  148.  
  149.     Strings matrices, belong to the string class, and not the
  150.     numeric class. String matrices have a different internal
  151.     representation than numeric matrices. String matrices can not
  152.     be operated on with numeric matrices, or in the same fashion.
  153.  
  154.     The individual members are the same as RLaB's scalar string
  155.     object. The syntax for creating a string matrix is the same as
  156.     a numerical matrix, except the elements are strings, and not
  157.     numbers.
  158.  
  159.     > sm = [ "s-element-1,1", "s-element-1,2";
  160.     >        "s-element-2,1", "s-element-2,2"]
  161.      sm =
  162.     s-element-1,1  s-element-1,2  
  163.     s-element-2,1  s-element-2,2  
  164.  
  165.     > sm[1;2]
  166.     s-element-1,2
  167.     > sm[3]
  168.     s-element-1,2
  169.  
  170.     > show ( sm )
  171.        name:      sm      
  172.        class:     string  
  173.        type:              
  174.          nr:      2       
  175.          nc:      2       
  176.  
  177.     > show ( sm[1;1] )
  178.        name:      NULL    
  179.        class:     string  
  180.         type:             
  181.          nr:      1       
  182.          nc:      1       
  183.