HP 3000 Manuals

MAT = [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation


HP Business BASIC/XL Reference Manual

MAT = 

The MAT = statement assigns the value of an expression to an array.  Some
forms of the MAT statement can redimension the array before the
assignment.

Syntax 

The numbers preceding these syntax specifications are referenced in Table
4-5.  They are not part of the MAT statement syntax.

(1) MAT num_array1 = num_array2 

(2) MAT num_array1 = (num_expr)

(3a) MAT num_array1 = num_array2 op (num_expr)

(3b) MAT num_array1 = (num_expr) op num_array2 

(4) MAT num_array1 = num_array2 op num_array3 

                     {CON}
(5) MAT num_array1 = {ZER} [(dims)]
                     {IDN}

(6) MAT num_array1 = s_or_a_function (num_array2)

(7) MAT num_array1 = array_function (num_array2)

(8) MAT num_array1 = MUL (num_array2, num_array3)

Parameters 

op                  +, -, *, /, <, <=, =,>=, <>, or #

num_array1          In equation (4), num_array1 must have the same number
                    of dimensions as num_array2 and num_array3.  It must
                    have at least as many elements as each of num_array2 
                    and num_array3.

num_array3          In equation (4), num_array3 must have the same number
                    of dimensions as num_array2.  Each dimension of
                    num_array3 must have the same number of elements as
                    the corresponding dimension of num_array2.  However,
                    corresponding dimensions of num_array3 and num_array2 
                    can have different bounds (for example, num_array2 
                    can be declared "DIM A(1:2,1:4)" and num_array3 can
                    be declared "DIM B(2:3,2:5)").

                    In equation (8), num_array2 and num_array3 can both
                    be matrices, or one can be a matrix and one can be a
                    vector.  The dimensions of num_array2 and num_array3 
                    are subject to the restrictions in Table 4-6.

CON                 Sets each element of array to one.

ZER                 Sets each element of array to zero.

IDN                 Makes array an identity matrix.  If dims is
                    specified, it must specify a square matrix.  If dims 
                    is not specified, array must be a square matrix.

dims                If specified, the statement redimensions num_array1 
                    before assigning values to its elements.

s_or_a_function     A scalar or array function; one of the following:

                         ABS       ACS        ASN        ATN     CEIL      LGT
                         DECIMAL   EXP        FRACT      INT     INTEGER   LOG
                         REAL      SDECIMAL   SGN        SIN     SINTEGER  SQR
                         SREAL     TAN        TRUNC      COS

                    See chapter 5 for more information about these
                    functions.

array_function      See chapter 5 and Table 4-6 for more information
                    about these functions.

                    CSUM                Stores column sums of matrix in
                                        vector.

                    RSUM                Stores row sums of matrix in
                                        vector.

                    TRN                 Transposes rows and columns of
                                        matrix.

                    INV                 Inverts square matrix.

                    MUL                 Multiplies two matrices or a
                                        vector and a matrix.

Table 4-5 through Table 4-6 give more information about the MAT =
statement.

Table 4-5        Gives the new dimensions of and value of num_array1 for
                 each form of the MAT = statement.

Table 4-6        Shows how the dimensions of num_array2 and num_array3 
                 determine the new dimensions of num_array1.

          Table 4-5.  Forms of MAT = Statement 

-----------------------------------------------------------------------------------------------
|          |                                    |                                             |
|   Form   |      Redimensions num_array1       |    Where num_array1(i) and num_array2(i)    |
|          |          to Dimension of:          | are Corresponding Elements:  num_array1(i)= |
|          |                                    |                                             |
-----------------------------------------------------------------------------------------------
|          |                                    |                                             |
| 1        | num_array2                         | num_array2(i)                               |
|          |                                    |                                             |
-----------------------------------------------------------------------------------------------
|          |                                    |                                             |
| 2        | Does not redimension               | num_expr                                    |
|          |                                    |                                             |
|          | num_array1                         |                                             |
|          |                                    |                                             |
-----------------------------------------------------------------------------------------------
|          |                                    |                                             |
| 3a       | num_array2                         | num_array2(i) op num_expr                   |
|          |                                    |                                             |
-----------------------------------------------------------------------------------------------
|          |                                    |                                             |
| 3b       | num_array2                         | num_expr op num_array2(i)                   |
|          |                                    |                                             |
-----------------------------------------------------------------------------------------------
|          |                                    |                                             |
| 4        | num_array2,                        | num_array2(i) op num_array3(i)              |
|          |                                    |                                             |
|          | num_array3                         |                                             |
|          | (same)                             |                                             |
|          |                                    |                                             |
-----------------------------------------------------------------------------------------------
|          |                                    |                                             |
| 5        | Specified dimensions, if any       | ZER: 0                                      |
|          |                                    | CON: 1                                      |
|          |                                    | IDN: 1 if it is on the top-left-to-bottom-ri|ht
|          |                                    | diagonal; 0 otherwise                       |
|          |                                    |                                             |
-----------------------------------------------------------------------------------------------
|          |                                    |                                             |
| 6        | num_array2                         | scalar_or_array_function (num_array2)       |
|          |                                    |                                             |
-----------------------------------------------------------------------------------------------
|          |                                    |                                             |
| 7        | See Table 4-6                      | See Table 4-6                               |
|          |                                    |                                             |
| 8        |                                    |                                             |
|          |                                    |                                             |
-----------------------------------------------------------------------------------------------

          Table 4-6.  Dimensions of Array Function Arguments and Results 

-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
|         Array         |     Dimensions of     |     Dimensions of     |     Dimensions of     |
|       Function        |      num_array2       |      num_array3       |  num_array1 (result)  |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
| CSUM                  |         (m,n)         |    Not applicable     |          (n)          |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
| RSUM                  |         (m,n)         |    Not applicable     |          (m)          |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
| TRN                   |         (m,n)         |    Not applicable     |         (n,m)         |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
| INV                   |         (m,m)         |    Not applicable     |         (m,m)         |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
| MUL                   |         (m,n)         |         (n,p)         |         (m,p)         |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
| MUL                   |         (m,n)         |          (n)          |          (m)          |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
| MUL                   |          (m)          |         (m,p)         |          (p)          |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------

Examples 

          10 DIM A(4),B(4),C(4),D(4),E(2,4),F(2)
          20 READ (FOR I=1 TO 4,A(I))
          30 READ (FOR I=1 TO 2,(FOR J=1 TO 4,E(I,J)))
          40 !
          50  !  Form 1:
          60 MAT B=A           !B has the same elements as A, B(1) = A(1), etc
          70 !
          80 !  Form 2:
          90 MAT C=(2+3)       !All elements of C have the value of 5
         100 !
         110 !  Form 3:
         120 MAT D=(2)*B       ! All elements of D are worth 2 * B, D(1) =20 ,etc
         130 MAT D=B*(2)       !Alternate form 3b, results are the same as line 61
         140 !
         150 !  Form 4:
         160 MAT C=A+B         !Each element, I of C is the total of A(I) + B(I)
         170 !
         180 !  Form 5:
         190 MAT B=CON         ! Each element of B is now 1
         200 !
         210 !  Form 6:
         220 MAT D=SQR(A)      ! Each element, I of D is now the square root of A(I)
         230 !
         240 !  Form 7:
         250 MAT C=CSUM(E)     ! Each element, I of C is now the sum of the entries
         260                   ! in column I of E
         270 !
         280 !  Form 8:
         290 MAT F=MUL(E,A)    ! Array F contains the result of the matrix
         300                   ! multiplication of E and A
         310 !
         320 !
         330 DATA 10,20,30,40
         340 DATA 1,2,3,4,5,6,7,8
         999 END



MPE/iX 5.0 Documentation