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 ADD a()=b()+c() MAT ADD a(),b() MAT ADD a(),x MAT SUB a()=b()-c() MAT SUB a(),b() MAT SUB a(),x MAT MUL a()=b()*c() MAT MUL x=a()*b() MAT MUL x=a()*b()*c() MAT MUL a(),x MAT NORM a(),0 MAT NORM a(),1 MAT DET x=a([i,j])[,n] MAT QDET x=a([i,j])[,n] MAT RANG x=a([i,j])[,n] MAT INV a()=b() a, b, c: names of numerical floating point fields x: aexp (scalar value) i, j, n: aexp MAT ADD a()=b()+c() is only defined for matrix (vectors) of the same order, e.g. DIM a(n,m),b(m,m),c(n,m) or DIM a(n),b(n),c(n). Array c is added to matrix b, element by element, and the result is written to matrix a. Example: DIM a(3,5),b(3,5),c(3,5) MAT SET b()=3 MAT SET c()=4 MAT PRINT b() PRINT STRING$(10,"-") MAT PRINT c() PRINT STRING$(10,"-") MAT ADD a()=b()+c() MAT PRINT a() --> Outputs: 3,3,3,3,3 3,3,3,3,3 3,3,3,3,3 --------- 4,4,4,4,4 4,4,4,4,4 4,4,4,4,4 --------- 7,7,7,7,7 7,7,7,7,7 7,7,7,7,7 MAT ADD a(),b() is only defined for matrix (vectors) of the same order, e.g. DIM a(n,m),b(n,m) or DIM a(n),b(n). Array b is added to matrix a, element by element, and the result is written to matrix a. The original matrix a is lost in the process. Example: DIM a(3,5),b(3,5) MAT SET a()=1 MAT SET b()=3 MAT PRINT a() PRINT STRING$(10,"-") MAT PRINT b() PRINT STRING$(10,"-") MAT ADD a(),b() MAT PRINT a() --> Outputs: 1,1,1,1,1 1,1,1,1,1 1,1,1,1,1 --------- 3,3,3,3,3 3,3,3,3,3 3,3,3,3,3 --------- 4,4,4,4,4 4,4,4,4,4 4,4,4,4,4 MAT ADD a(),x is defined for all matrix (vectors). Here, the scalar x is added to matrix a, element by element, and the result is written to matrix a. The original matrix a is lost in the process. Example: DIM a(3,5) MAT SET a()=1 MAT PRINT a() PRINT STRING$(10,"-") MAT ADD A(),5 MAT PRINT a() --> Outputs: 1,1,1,1,1 1,1,1,1,1 1,1,1,1,1 --------- 6,6,6,6,6 6,6,6,6,6 6,6,6,6,6 MAT SUB a()=b()-c() is only defined for matrix (vectors) of the same order, e.g. DIM a(n,m),b(n,m),c(n,m) or DIM a(n),b(n),c(n). Array c is subtracted from matrix b, element by element, and the result is written to matrix a. Example: DIM a(3,5),b(3,5),c(3,5) MAT SET b()=5 MAT SET c()=3 MAT PRINT b() PRINT STRING$(10,"-") MAT PRINT c() PRINT STRING$(10,"-") MAT SUB a()=b()-c() MAT PRINT a() --> Outputs: 5,5,5,5,5 5,5,5,5,5 5,5,5,5,5 --------- 3,3,3,3,3 3,3,3,3,3 3,3,3,3,3 --------- 2,2,2,7,2 2,2,2,2,2 2,2,2,2,2 MAT SUB a(),b() is only defined for matrix (vectors) of the same order, e.g. DIM a(n,m),b(n,m) or DIM a(n),b(n). Array b is subtracted from matrix a, element by element, and the result written to matrix a. The original matrix a is lost in the process. Example: DIM a(3,5),b(3,5) MAT SET a()=3 MAT SET b()=1 MAT PRINT a() PRINT STRING$(10,"-") MAT PRINT b() PRINT STRING$(10,"-") MAT SUB a(),b() MAT PRINT a() --> Outputs: 3,3,3,3,3 3,3,3,3,3 3,3,3,3,3 --------- 1,1,1,1,1 1,1,1,1,1 1,1,1,1,1 --------- 2,2,2,2,2 2,2,2,2,2 2,2,2,2,2 MAT SUB a(),x is defined for all matrix (vectors). Here, the scalar x is subtracted from matrix x, element by element, and the result is written to matrix a. The original matrix a is lost in the process. Example: DIM a(3,5) MAT SET a()=6 MAT PRINT a() PRINT STRING$(10,"-") MAT SUB A(),5 MAT PRINT a() --> Outputs: 6,6,6,6,6 6,6,6,6,6 6,6,6,6,6 --------- 1,1,1,1,1 1,1,1,1,1 1,1,1,1,1 MAT MUL a()=b()*c() is defined for matrix of an "appropriate" order. Arrays b and c are multiplied with each other. The result of this multiplication is written to matrix a. In order for the result to be defined, the matrix on the left (matrix b in this case) must have the same number of columns as the matrix on the right (c in this case) has rows. Array a, in this case, must have as many rows as b and as many columns as c, for example: DIM a(2,2),b(2,3),c(3,2) Arrays are multiplied as "row by column", i.e. element a(i,j) is obtained by multiplying the elements in the ith row of matrix b with the elements in the jth column of matrix c, element by element, and then adding up the individual products. Example: DIM a(2,2),b(2,3),c(3,2) MAT SET b()=1 DATA 1,2,-3,4,5,-1 MAT READ c() MAT PRINT b(),5,1 PRINT STRING$(18,"-") MAT PRINT c(),5,1 PRINT STRING$(18,"-") MAT MUL a()=b()*c() MAT PRINT a(),5,1 --> Outputs: 1.0, 1.0, 1.0 1.0, 1.0, 1.0 ------------------ 1.0, 2.0 -3.0, 4.0 5.0, -1.0 ------------------ 3.0, 5.0 3.0, 5.0 With vectors instead of matrix, MAT MUL a()=b()*c() results in the dyadic (or external) product of two vectors. Example: DIM a(3,3),b(3),c(3) DATA 1,2,-3,4,5,-1 MAT READ b() MAT READ c() MAT PRINT b(),5,1 PRINT STRING$(18,"-") MAT PRINT c(),5,1 PRINT STRING$(18,"-") MAT MUL a()=b()*c() MAT PRINT a(),5,1 --> Outputs: 1.0, 2.0, -3.0 ------------------ 4.0, 5.0, -1.0 ------------------ 4.0, 5.0, -1.0 5.0, 10.0, -2.0 -12.0, -15.0, 3.0 MAT MUL x=a()*b() is only defined for vectors with an equal number of elements. The result x is the scalar product (the so-called interior product) of vectors a and b. The scalar product of two vectors is defined as the sum of n products a(i)*b(i),i=1,...,n. Example: DIM b(3),c(3) DATA 1,2,-3,4,5,-1 MAT READ b() MAT READ c() MAT PRINT b(),5,1 PRINT STRING$(18,"-") MAT PRINT c(),5,1 PRINT STRING$(18,"-") MAT MUL x=b()*c() PRINT x --> Outputs: 1.0, 2.0, -3.0 ------------------ 4.0, 5.0, -1.0 ------------------ 17.0 MAT MUL x=a()*b()*c() is defined for qualified Vectors a and c as well as qualified Matrix b(). Example: DIM a(2).b(2,3),c(3) DATA 1,2,-3,4,5 MAT READ a() MAT READ c() MAT SET b()=1 MAT PRINT a(),5,1 PRINT STRING$(18,"-") MAT PRINT b(),5,1 PRINT STRING$(18,"-") MAT PRINT c(),5,1 PRINT STRING$(18,"-") MAT MUL x=a()*b()*c() PRINT x --> Outputs: 1.0, 2.0 ------------------ 1.0, 1.0, 1.0 1.0, 1.0, 1.0 1.0, 1.0, 1.0 ------------------ -3.0, 4.0, 5.0 ------------------ 18.0 MAT NORM a(),0 or MAT NORM a(),1 are defined for matrix and vectors. MAT NORM a(),0 normalises a matrix (a vector) by rows, MAT NORM a(),1 by columns. This means that after a normalisation by rows (by columns) the sum of the squares of all elements in each row (column) is identical at 1. Example: DIM a(10,10),b(10,10),v(10) DATA 1,2,3,4,5,6,7,8,9,-1 DATA 3.2,4,-5,2.4,5.1,6.2,7.2,8.1,6,-5 DATA -2,-5,-6,-1.2,-1.5,-6.7,4.5,8.1,3.4,10 DATA 5,-2.3,4,5.6,12.2,18.2,14.1,16,-21,-13 DATA 4.1,5.2,16.7,18.4,19.1,20.2,13.6,14.8,19.4,18.6 DATA 15.2,-1.8,13.6,-4.9,5.4,19.8,16.4,-20.9,21.4,13.8 DATA -3.6,6,-8.2,-9.1,4,-2.5,2,3.4,6.7,8.4 DATA 4.7,8.3,9.4,10.5,11,19,15.4,18.9,-20,12.6 DATA 5.3,-4.7,6.1,6.5,6.9,-9.2,-10.8,4.3,5.6,9.1 DATA 21.4,19.5,28.4,19.3,24.6,14.9,71.3,23.5,14.5,-12.3 ' CLS MAT READ a() MAT CPY b()=a() !Source matrix stored PRINT "Source matrix" PRINT MAT PRINT a(),7,2 ~INP(2) CLS MAT NORM a(),0 PRINT PRINT "Row:" PRINT MAT PRINT a(),7,2 ~INP(2) ' PRINT PRINT "Test:" PRINT FOR i%=1 TO 10 MAT XCPY v()=a(i%,1) MAT MUL x=v()*v() PRINT x' NEXT i% PRINT ~INP(2) ' CLS MAT CPY a()=b() MAT NORM a(),1 PRINT "Column:" PRINT MAT PRINT a(),7,2 ~INP(2) ' PRINT PRINT "Test:" PRINT FOR i%=1 TO 10 MAT CPY v()=a(1,i%) !Copy column a() in the vector v() MAT MUL x=v()*v() PRINT x' NEXT i% ~INP(2) --> Outputs: Source matrix 1.00, 2.00, 3.00, 4.00, 5.00, 6.00, 7.00, 8.00, 9.00, -1.00 3.20, 4.00, -5.00, 2.40, 5.10, 6.20, 7.20, 8.10, 6.00, -5.00 -2.00, -5.00, -6.00, -1.20, -1.50, -6.70, 4 50, 8.10, 3.40, 10.00 5.00, -2.30, 4.00, 5.60, 12.20, 18.20, 14.10, 16.00, -21.00, -13.00 4.10, 5.20, 16.70, 18.40, 19.10, 20.20, 13.60, 14.80, 19.40, 18.60 15.20, -1.80, 13.60, -4.90, 5.40, 19.80, 16.40, -20.90, 21.40, 13.80 -3.60, 6.00, -8.20, -9.10, 4.00, -2.50, 2.00, 3.40, 6.70, 8.40 4.70, 8.30, 9.40, 10.50, 11.00, 19.00, 15.40, 18.90, -20.00, 12.60 5.30, -4.70, 6.10, 6.50, 6.90, -9.20, -10.80, 4.30, 5.60, 9.10 21.40, 19.50, 28.40, 19.30, 24.60, 14.90, 71.30, 23.50, 14.50, -12.30 Row: 0.06, 0.12, 0.18, 0.24, 0.30, 0.35, 0.41, 0.47, 0.53, -0.06 0.18, 0.23, -0.29, 0.14, 0.29, 0.36, 0.42, 0.47, 0.35, -0.29 -0.11, -0.28, -0.34, -0.07, -0.09, -0.38, 0.26, 0.46, 0.19, 0.57 0.12, -0.06, 0.10, 0.14, 0.30, 0.45, 0.35, 0.40, -0.52, -0.32 0.08, 0.10, 0.33, 0.36, 0.38, 0.40, 0.27, 0.29, 0.38, 0.37 0.32, -0.04, 0.29, -0.10, 0.11, 0.42, 0.35, -0.44, 0.45, 0.29 -0.19, 0.32, -0.44, -0.48, 0.21, -0.13, 0.11, 0.18, 0.36, 0.45 0.11, 0.19, 0.21, 0.24, 0.25, 0.43, 0.35, 0.43, -0.46, 0.29 0.23, -0.21, 0.27, 0.29, 0.31, -0.41, -0.48, 0.19, 0.25, 0.40 0.23, 0.21, 0.30, 0.21, 0.26, 0.16, 0.76, 0.25, 0.15, -0.13 Test: 1 1 1 1 1 1 1 1 1 1 Columns: 0.04, 0.08, 0.08, 0.12, 0.13, 0.14, 0.09, 0.18, 0.20, -0.03 0.11, 0.16, -0.13, 0.07, 0.14, 0.14, 0.09, 0.18, 0.13, -0.14 -0.07, -0.21, -0.15, -0.04, -0.04, -0.15, 0.06, 0.18, 0.07, 0.28 0.18, -0.09, 0.10, 0.17, 0.33, 0.41, 0.18, 0.35, -0.46, -0.36 0.14, 0.21, 0.42, 0.57, 0.51, 0.46, 0.17, 0.33, 0.42, 0.52 0.53, -0.07, 0.35, -0.15, 0.15, 0.45, 0.21, -0.46, 0.47, 0.38 -0.13, 0.25, -0.21, -0.28, 0.11, -0.06, 0.03, 0.08, 0.15, 0.23 0.17, 0.34, 0.24, 0.33, 0.30, 0.43, 0.20, 0.42, -0.44, 0.35 0.19, -0.19, 0.15, 0.20, 0.19, -0.21, -0.14, 0.10, 0.12, 0.25 0.75, 0.80, 0.72, 0.60, 0.66, 0.34, 0.90, 0.52, 0.32, -0.34 Test: 1 1 1 1 1 1 1 1 1 1 MAT DET x=a([i,j])[,n] calculates the determinants of a square matrix of the (n,n) type. The row and column offsets are preset to a(0,0) or a(1,1), depending on MAT BASE 0 or MAT BASE 1, assuming that OPTION BASE 1 is enabled. It is also possible, however, to calculate the determinant of a square part matrix. To do this, the row and column offsets of a() must be specified as i and j, and the number of elements in the part matrix as n. A part matrix of the (n,n) type is then created internally starting from the "position" ith row, jth column. Example: DIM a(10,10),b(4,4) DATA 1,2,3,4,5,6,7,8,9,-1 DATA 3.2,4,-5,2.4,5.1,6.2,7.2,8.1,6,-5 DATA -2,-5,-6,-1.2,-1.5,-6.7,4.5,8.1,3.4,10 DATA 5,-2.3,4,5.6,12.2,18.2,14.1,16,-21,-13,3.8 DATA 4.1,5.2,16.7,18.4,19.1,20.2,13.6,14.8,19.4,18.6 DATA 15.2,-1.8,13.6,-4.9,5.4,19.8,16.4,-20.9,21.4,13.8 DATA -3.6,6,-8.2,-9.1,4,-2.5,2,3.4,6.7,8.4,10.9 DATA 4.7,8.3,9.4,10.5,11,19,15.4,18.9,-20,12.6 DATA 5.3,-4.7,6.1,6.5,6.9,-9.2,-10.8,4.3,5.6,9.1 DATA 21.4,19.5,28.4,19.3,24.6,14.9,71.3,23.5,14.5,-12.3 ' CLS MAT READ a() PRINT "Source matrix" PRINT MAT PRINT a(),7,2 PRINT PRINT "Determinant: "; MAT DET x=a() PRINT x; MAT DET y=a(1,4),4 PRINT PRINT "Determinant from a(1,4),4: "; PRINT y PRINT PRINT "Test: " PRINT MAT CPY b()=a(1,4),4,4 !copy to b() MAT PRINT b(),7,2 MAT DET z=b() !Determinant from b() PRINT PRINT z --> Outputs: Source Matrix 1.00, 2.00, 3.00, 4.00, 5.00, 6.00, 7.00, 8.00, 9.00, -1.00 3.20, 4.00, -5.00, 2.40, 5.10, 6.20, 7.20, 8.10, 6.00, -5.00 -2.00, -5.00, -6.00, -1.20, -1.50, -6.70, 4.50, 8.10, 3.40, 10.00 5.00, -2.30, 4.00, 5.60, 12.20, 18.20, 14.10, 16.00, -21.00, -13.00 3.80, 4.10, 5.20, 16.70, 18.40, 19.10, 20.20, 13.60, 14.80, 19.40 18.60, 15.20, -1.80, 13.60, -4.90, 5.40, 19.80, 16.40, -20.90, 21.40 13.80, -3.60, 6.00, -8.20, -9.10, 4.00, -2.50, 2.00, 3.40, 6.70 8.40, 10.90, 4.70, 8.30, 9.40, 10.50, 11.00, 19.00, 15.40, 18.90 -20.00, 12.60, 5.30, -4.70, 6.10, 6.50, 6.90, -9.20, -10.80, 4.30 5.60, 9.10, 21.40, 19.50, 28.40, 19.30, 24.60, 14.90, 71.30, 23.50 Determinant: -2549840202186 Determinant from a(1,4),4: -57.61200000001 Test: 4.00, 5.00, 6.00, 7.00 2.40, 5.10, 6.20, 7.20 -1.20, -1.50, -6.70, 4.50 5.60, 12.20, 18.20, 14.10 -57.61200000001 MAT QDET x=a([i,j])[,n] works in the same manner as MAT DET x=a([i,j])[,n], except that it has been optimized for speed rather than accuracy. Both will normally produce identical results. With "critical" matrix, whose determinant is close to 0, you should always use MAT DET, though. Example: DIM a(10,10) DATA 1,2,3,4,5,6,7,8,9,-1 DATA 3.2,4,-5,2.4,5.1,6.2,7.2,8.1,6,-5 DATA -2,-5,-6,-1.2,-1.5,-6.7,4.5,8.1,3.4,10 DATA 5,-2.3,4,5.6,12.2,18.2,14.1,16,-21,-13,3.8 DATA 4.1,5.2,16.7,18.4,19.1,20.2,13.6,14.8,19.4,18.6 DATA 15.2,-1.8,13.6,-4.9,5.4,19.8,16.4,-20.9,21.4,13.8 DATA -3.6,6,-8.2,-9.1,4,-2.5,2,3.4,6.7,8.4,10.9 DATA 4.7,8.3,9.4,10.5,11,19,15.4,18.9,-20,12.6 DATA 5.3,-4.7,6.1,6.5,6.9,-9.2,-10.8,4.3,5.6,9.1 DATA 21.4,19.5,28.4,19.3,24.6,14.9,71.3,23.5,14.5,-12.3 ' CLS MAT READ a() PRINT "Source matrix" PRINT MAT PRINT a(),7,2 PRINT PRINT "Determinant with MAT DET: "; MAT DET x=a() PRINT x; PRINT PRINT "Determinant with MAT QDET: "; MAT DET y=a() PRINT y; PRINT PRINT "Deviation: ";x-y --> Outputs: Source Matrix 1.00, 2.00, 3.00, 4.00, 5.00, 6.00, 7.00, 8.00, 9.00, -1.00 3.20, 4.00, -5.00, 2.40, 5.10, 6.20, 7.20, 8.10, 6.00, -5.00 -2.00, -5.00, -6.00, -1.20, -1.50, -6.70, 4.50, 8.10, 3.40, 10.00 5.00, -2.30, 4.00, 5.60, 12.20, 18.20, 14.10, 16.00, -21.00, -13.00 3.80, 4.10, 5.20, 16.70, 18.40, 19.10, 20.20, 13.60, 14.80, 19.40 18.60, 15.20, -1.80, 13.60, -4.90, 5.40, 19.80, 16.40, -20.90, 21.40 13.80, -3.60, 6.00, -8.20, -9.10, 4.00, -2.50, 2.00, 3.40, 6.70 8.40, 10.90, 4.70, 8.30, 9.40, 10.50, 11.00, 19.00, 15.40, 18.90 -20.00, 12.60, 5.30, -4.70, 6.10, 6.50, 6.90, -9.20, -10.80, 4.30 5.60, 9.10, 21.40, 19.50, 28.40, 19.30, 24.60, 14.90, 71.30, 23.50 Determinant with MAT DET: -2549840202186 Determinant with MAT QDET: -2549840202186 Deviation: 0 MAT RANG x=a([i,j])[,n] outputs the rank of a square matrix. As with MAT DET or MAT QDET, you can select any row and column offset. The number of elements in the part matrix must be specified with n. This creates a part matrix of the (n,n) type internally, starting from the position ith row, jth column. Example: DIM a(5,5) DATA 1,2,3,4,5 DATA 3.2,4,-5,2.4,5.1 DATA -2,4,-5,2.4,5.1 DATA 5,-2.3,4,5.6,12.2 DATA 4.1,5.2,16.7,18.4,19.1 ' CLS MAT READ a() PRINT "Source matrix" PRINT MAT PRINT a(),7,2 PRINT PRINT "Rang from a(): "; MAT RANG x=a() PRINT x; PRINT PRINT "Rang from a(1,2),3: "; MAT RANG y=a(1,2),3 PRINT y; PRINT --> Outputs: Source matrix 1.00, 2.00, 3.00, 4.00, 5.00 3.20, 4.00, -5.00, 2.40, 5.10 -2.00, 4.00, -5.00, 2.40, 5.10 5.00, -2.30, 4.00, 5.60, 12.20 4.10, 5.20, 16.70, 18.40, 19.10 Rang from a(): 5 Rang from a(1,2),3: 2 MAT INV b()=a() is used to determine the inverses of a square matrix. The inverse of matrix a() is written to matrix b(), hence b() must be of the same type as a(). Example: DIM a(5,5),b(5,5),c(5,5) DATA 1,2,3,4,5 DATA 3.2,4,-5,2.4,5.1 DATA -2,4,-5,2.4,5.1 DATA 5,-2.3,4,5.6,12.2 DATA 4.1,5.2,16.7,18.4,19.1 ' CLS MAT READ a() PRINT "Source matrix a(): " PRINT MAT PRINT a(),7,2 ' MAT INV b()=a() PRINT PRINT "Inverse from a(): " PRINT MAT PRINT b(),7,2 PRINT PRINT "Test b()*a()>Unity matrix ?" PRINT MAT MUL c()=b()*a() MAT PRINT c(),7,2 --> Outputs: Source matrix a(): 1.00, 2.00, 3.00, 4.00, 5.00 3.20, 4.00, -5.00, 2.40, 5.10 -2.00, 4.00, -5.00, 2.40, 5.10 5.00, -2.30, 4.00, 5.60, 12.20 4.10, 5.20, 16.70, 18.40, 19.10 Inverse from a(): 0.00, 0.19, -0.19, -0.00, -0.00 0.97, 0.02, -0.09, -0.10, -0.17 0.71, -0.10, -0.10, -0.01, -0.12 -1.65, 0.17, 0.11, -0.06, 0.39 0.71, -0.12, 0.04, 0.09, -0.17 Test b()*a()>Unity matrix ? 1.00, 0.00, 0.00, 0.00, 0.00 0.00, 1.00, 0.00, 0.00, -0.00 0.00, -0.00, 1.00, 0.00, -0.00 -0.00, -0.00, -0.00, 1.00, 0.00 -0.00, 0.00, 0.00, 0.00, 1.00 Memo: MAT DET x=a(i,j),n !causes the compiler to crash MAT DET x=a(i,j),2+6 !is also fatal MAT DET x=a(i,j),4 !seems to compile ok MAT DET x=a(i,j),n& !seems to compile ok MAT QDET and MAT RANG seem to have the same problems.