Topic : The GFA-Basic Compendium Author : GFA Systemtechnik GmbH Version : GFABasic.HYP v2.98 (12/31/2023) Subject : Documentation/Programming Nodes : 899 Index Size : 28056 HCP-Version : 3 Compiled on : Atari @charset : atarist @lang : @default : Document not found @help : Help @options : +g -i -s +z @width : 75 @hostname : STRNGSRV @hostname : CAB @hostname : HIGHWIRE @hostname : THING View Ref-FileMAT CPY a([i,j])=b([k,l])[,h,w] MAT XCPY a([i,j])=b([k,l])[,h,w] MAT TRANS a()[=b()] a, b: name of fields with numerical variables i, j, k, l, h, w: iexp MAT CPY a([i,j])=b([k,l])[,h,w] copies h rows with w elements each from matrix b to the row and column offset of matrix a defined by i,j, starting from the row and column offset of matrix b defined by l,k. Example: DIM a(5,5),b(4,4) MAT SET a()=1 FOR i%=1 TO 4 FOR j%=1 TO 4 b(i%,j%)=SUC(i%) NEXT j% NEXT i% ' MAT PRINT a() PRINT "---------" MAT PRINT b() PRINT "---------" MAT CPY a(2,2)=b(2,2),3,3 --> Outputs: 1,1,1,1,1 1,1,1,1,1 1,1,1,1,1 1,1,1,1,1 1,1,1,1,1 --------- 2,2,2,2 3,3,3,3 4,4,4,4 5,5,5,5 --------- 1,1,1,1,1 1,3,3,3,1 1,4,4,4,1 1,5,5,5,1 1,1,1,1,1 Special Cases MAT CPY a()=b() copies the complete matrix b into matrix a if the matrix are of the same order. Only those elements are copied in this process for which identical indices are given in both the source and the destination matrix. Example: DIM a(5,3),b(4,4) MAT SET a()=1 FOR i%=1 TO 4 FOR j%=1 TO 4 b(i%,j%)=SUCC(i%) NEXT j% NEXT i% ' MAT PRINT a() PRINT "-------" MAT PRINT b() PRINT "-------" MAT CPY a()=b(),3,3 MAT PRINT a() --> Outputs: 1,1,1 1,1,1 1,1,1 1,1,1 1,1,1 ------- 2,2,2,2 3,3,3,3 4,4,4,4 5,5,5,5 ------- 2,2,2 3,3,3 4,4,4 1,1,1 1,1,1 MAT CPY a(i,j)=b() copies matrix b, starting from the row and column offset defined by MAT BASE, to the row and column offset of matrix a defined by i,j. Only those elements are copied for which identical indices are given in both the source and the destination matrix. Example: DIM a(5,3),b(4,4) MAT SET a()=1 FOR i%=1 TO 4 FOR j%=1 TO 4 b(i%,j%)=SUCC(i%) NEXT j% NEXT i% ' MAT PRINT a() PRINT "-------" MAT PRINT b() PRINT "-------" MAT CPY a(2,2)=b(2,2),3,3 MAT PRINT a() --> Outputs: 1,1,1 1,1,1 1,1,1 1,1,1 1,1,1 ------- 2,2,2,2 3,3,3,3 4,4,4,4 5,5,5,5 ------- 1,1,1 1,3,3 1,4,4 1,5,5 1,1,1 MAT CPY a()=b(i,j) copies matrix b, starting from the row and column offset defined by i,j, to the offset of matrix a defined by MAT BASE. Only those elements are copied for which identical indices are given in both the source and the destination matrix. Example: DIM a(5,3),b(4,4) MAT SET a()=1 FOR i%=1 TO 4 FOR j%=1 TO 4 b(i%,j%)=SUCC(i%) NEXT j% NEXT i% ' MAT PRINT a() PRINT "-------" MAT PRINT b() PRINT "-------" MAT CPY a()=b(2,2),3,3 MAT PRINT a() --> Outputs: 1,1,1 1,1,1 1,1,1 1,1,1 1,1,1 ------- 2,2,2,2 3,3,3,3 4,4,4,4 5,5,5,5 ------- 3,3,3 4,4,4 5,5,5 1,1,1 1,1,1 MAT CPY a(i,j)=b(k,l) copies matrix b, starting from the row and column offset defined by k,l, to the offset i,j of matrix a. Only those elements are copied for which identical indices are given in both the source and the destination matrix. Example: DIM a(5,3),b(4,4) MAT SET a()=1 FOR i%=1 TO 4 FOR j%=1 TO 4 b(i%,j%)=SUCC(j%) NEXT j% NEXT i% ' MAT PRINT a() PRINT "-------" MAT PRINT b() PRINT "-------" MAT CPY a()=b() MAT PRINT a() --> Outputs: 1,1,1 1,1,1 1,1,1 1,1,1 1,1,1 ------- 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 ------- 1,1,1 1,3,4 1,3,4 1,3,4 1,1,1 MAT CPY a()=b() copies h rows with w elements each from the matrix b, starting from the row and column offset defined by MAT BASE, the row and column offset of matrix a defined by MAT BASE. Only those elements are copied for which identical indices are given in both the source and the destination matrix. Example: DIM a(5,3),b(4,4) MAT SET a()=1 FOR i%=1 TO 4 FOR j%=1 TO 4 b(i%,j%)=SUCC(j%) NEXT j% NEXT i% ' MAT PRINT a() PRINT "-------" MAT PRINT b() PRINT "-------" MAT CPY a(2,2)=b(2,2) MAT PRINT a() --> Outputs: 1,1,1 1,1,1 1,1,1 1,1,1 1,1,1 ------- 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 ------- 2,3,4 2,3,4 2,3,4 2,3,4 1,1,1 MAT XCPY a([i,j])=b([k,l])[,h,w] works basically in the same manner as MAT CPY a([i,j])=b([k,l])[,h,w], except that matrix b is being transposed while being copied to matrix a, i.e. the rows and columns of matrix b are swapped while it is copied to matrix a. Array b remains unchanged, however. Only those elements are copied for which identical indices are given in both the source and the destination matrix. Example: DIM a(5,3),b(4,4) MAT SET a()=1 FOR i%=1 TO 4 FOR j%=1 TO 4 b(i%,j%)=SUCC(j%) NEXT j% NEXT i% ' MAT PRINT a() PRINT "-------" MAT PRINT b() PRINT "-------" MAT XCPY a(2,2)=b(2,2),3,3 MAT PRINT a() --> Outputs: 1,1,1 1,1,1 1,1,1 1,1,1 1,1,1 ------- 2,3,4,5 2,3,4,5 2,3,4,5 2,3,4,5 ------- 1,1,1 1,3,3 1,4,4 1,5,5 1,1,1 Further Special Cases As with MAT CPY a(i,j)=b(k,l),w,h. If MAT CPY or MAT XCPY are applied to vectors, j and l may be ignored. Following a DIM a(n),b(m), a() and b() are interpreted as row vectors, i.e. as matrix of the (1,n) or (1,m) types. For a and b to be treated as column vectors, they must be dimensioned as matrix of the (n,1) or (m,1) type, ie. DIM a(n,1),b(n,1). If both vectors are of the same order (both are row or column vectors), MAT CPY must be used. Irrespective of the type of vectors a and b, MAT CPY always treats both vectors syntactically as column vectors, so that the correct syntax to be used for MAT CPY is always: MAT CPY a(n,1)=b(m,1)! Example: DIM a(10),b(5) !a() and b() are row vectors MAT SET a()=1 FOR i%=1 TO 5 b(i%)=SUCC(i%) NEXT i% PRINT "a(): "; MAT PRINT a() PRINT "b(): "; MAT PRINT b() PRINT STRING$(45,"-") MAT CPY a(3,1)=b(1,1) !interprets a() and b() as column vectors PRINT "MAT CPY a(3,1)=b(1,1): "; MAT PRINT a() --> Outputs: a(): 1,1,1,1,1,1,1,1,1,1 b(): 2,3,4,5,6 ------------------------------------------ MAT CPY a(3,1)=b(1,1): 1,1,2,3,4,5,6,1,1,1 For MAT XCPY, one of the two vectors a and b must be explicitly dimensioned as a row vector, the other as a column vector. For example: DIM a(1,10),b(5,1) Since MAT XCPY first transposes the second vector before copying it to the first. For this reason, MAT XCPY can only be used for DIM a(1,n),b(m,1): a()=row vector, b()=column vector and DIM a(n,1),b(1,m): a()=column vector, b()=row vector. Example: DIM a(1,10).n(5,1) MAT SET a()=1 FOR i%=1 TO 5 b(i%,1)=SUCC(i%) NEXT i% MAT PRINT a() PRINT MAT PRINT b() MAT XCPY a(1,3)=b(1,1) PRINT MAT PRINY a() --> Outputs: 1,1,1,1,1,1,1,1,1,1 2 3 4 5 6 1,1,2,3,4,5,6,1,1,1 Optionally, the parameters h and w can also be used when copying vectors with MAT CPY or MAT XCPY. However, the following applies: with MAT CPY, only the h parameter is used for w=>1. No copying takes place with w=0. With MAT XCPY, only h is used for w=>1 if b is a column vector to be copied into a row vector after transposition. No copying takes place when w=0. On the other hand, only w is used for h=>1 if b is a row vector which is to be copied to a column vector after transposition. In this case, no copying takes place if h=0. MAT TRANS a()=b() copies the transposed from matrix b to matrix a if a and b are dimensioned accordingly, i.e. the number of rows from a must correspond to the number of columns in b, and the number of columns from a to the number of rows of n: for example, DIM a(n,m),b(m,n). Example: DIM a(3,4),b(4,3) MAT SET b()=4 MAT SET a()=1 MAT PRINT a() PRINT STRING$(10,"-") MAT PRINT b() PRINT STRING$(10,"-") MAT TRANS a()=b() MAT PRINT a() --> Outputs: 1,1,1,1 1,1,1,1 1,1,1,1 ------- 4,4,4 4,4,4 4,4,4 4,4,4 ------- 4,4,4,4 4,4,4,4 4,4,4,4 In the case of a square matrix, i.e. one with equal numbers of rows and columns, MAT TRANS a() may be used. This command swaps the rows and columns of matrix a and writes the matrix thus changed back to a. The original matrix is lost in the process but can be restored with another MAT TRANS a(). Example: DIM a(5,5) FOR i%=1 TO 5 FOR j%=1 TO 5 a(i%,j%)=j% NEXT j% NEXT i% MAT PRINT a() PRINT STRING$(10,"-") MAT TRANS a() MAT PRINT a() --> Outputs: 1,2,3,4,5 1,2,3,4,5 1,2,3,4,5 1,2,3,4,5 1,2,3,4,5 --------- 1,1,1,1,1 2,2,2,2,2 3,3,3,3,3 4,4,4,4,4 5,5,5,5,5