New editor features in GFA BASIC 3.5E 1. The editor uses two more bytes per program row than the old editor (Versions 3.0 to 3.07). This accelerates the "backward scrolling" and makes it possible to fold func- tions, too (see 1-13). 2. You can now also use the "Search" function to search in the header rows of closed procedures or functions. 3. Listing now prints "labels" two characters to the left (as with CASE). 4. Tab functions Tab Cursor jumps to next tabulator position. Ctrl+Tab Cursor jumps the last previous tab position. LeftShift+Tab Inserts blank spaces to the next tab position. RightShift+Tab Deletes all blank spaces in one row up to or from cursor. 5. STE Support Version 3.5E has some new commands specific for use on the Atari STE computer: STICK(i) The values for 'i' on the STE can now be in the range 0 to 5. 0 and 1 act the same as normally found on the ST but 2 - 5 are exclusively for the STE, and DO NOT check for the mouse at the same time. This effectively speeds up the joystick polling. STRIG(i) This is the eqivalent Joystick Button command. The following commands are available for reading the STE's paddle controllers. PADX(i) This command gives the X position of one of the 2 paddles (i can be 0 or 1). PADY(i) The equivalent Y-Position. PADT(i) This command reads the paddle buttons. The following commands are available for reading the STE's lightpen socket. LPENX The X position of a connected lightpen. LPENY The Y position of a connected lightpen. You now have the ability to detect which computer your GFA programs are running on with the commands: STE? Returns -1 for STE(or TT), otherwise 0. TT? Returns -1 for 68020 or 68030 Processor, otherwise 0. DMACONTROL ctrlvar ctrlvar = 0 Stop sound. 1 Play sound once. 3 Play sound in loop. With the following command, you can play sampled DMA sound with the STE: DMASOUND beg,end,rate[,ctrl] beg = Sample start address. end = Sample end address. rate = Sample rate (0=6.25 kHz, 1=12.5 kHz, 2=25 kHz, 3=50 kHz). ctrl = See command DMACONTROL, (above) MWOUT mask,data This command controls the STE-Interne Micro-Wire-Interface, and is currently used for controlling sound. MWOUT &H7FF,x x=&X10 011 ddd ddd Set Master Volume 000 000 -80 dB 010 100 -40 dB 101 xxx 0 dB The value of the last 5 Bits is eqivalent to HALF of the volume in dB. x=&X10 101 xdd ddd Set Right Channel Volume 00 000 -40 dB 01 010 -20 dB 10 1xx 0 dB x=&X10 100 xdd ddd Set Right Channel Volume The last 4 Bits*2 = dB x=&X10 010 xxd ddd Set Treble x=&X10 001 xxd ddd Set Bass 0 000 -12dB 0 110 0 dB (flat) 1 100 +12 dB x=&X10 000 xxx xdd Set Mix 00 -12dB 01 Mix GI Sound (normaler ST) 10 Not Mix 11 Reserved Example: MWOUT &H7FF,&X10000000010 Switches the ST's sound off. In the following example, try each of the DMASOUND lines for different effects. PRINT STE? ! Prints -1 if an STE n%=360*32 DIM a|(n%) ' DMASOUND V:a|(0),V:a|(n%),0 ' DMASOUND V:a|(0),V:a|(n%),1 ' DMASOUND V:a|(0),V:a|(n%),2 DMASOUND V:a|(0),V:a|(n%),3,3 FOR i%=0 TO n% a|(i%)=128+SINQ(i%*i%/7200)*127 NEXT i% REPEAT UNTIL MOUSEK DMACONTROL 0 For the STE, MERGE'ing Basic files will stop when a right arrow, (Control-D), is found at the start of the line. SETCOLOR The STE's enhanced colour is now also supported, and the available 4096 colours can be accessed by use of SETCOLOR as normal, but the values can now be in the range of 0 to 15. Eg: SETCOLOR 2,13,13,13 6. Linear operations with vectors and matrix All functions described in this chapter relate only to one and/or two-dimensional fields with floating point variables. System commands MAT BASE 0 MAT BASE 1 The MAT BASE command can only sensibly be used when OPTION BASE 0 has been activated. In this case, MAT BASE 1 can be used to set the offset for the start of the row and column indexing of one or two-dimensional fields with floating point variables to 1 for the matrix operations. MAT BASE 0 resets this offset to 0 after a MAT BASE 1. Abbreviation: m b 0/m b 1 The setting made with MAT BASE n affects the following commands MAT READ MAT PRINT MAT CPY MAT XCPY MAT ADD MAT SUB MAT MUL The default is MAT BASE 1. Example: OPTION BASE 0 MAT BASE 1 DATA 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 DIM a(3,3) MAT READ a() PRINT a(1,1) Outputs value of 1 Generating commands MAT CLR a() MAT SET a()=x MAT ONE a() a: Name of field with numeric variables x: aexp MAT CLR a() corresponds to an ARRAYFILL a(),0, i.e. the command sets all elements in the field (matrix or vector) a() to a value of 0. Abbreviation: m cl a() MAT SET a()=x corresponds to an ARRAYFILL a(),x, i.e. the command sets all elements in the field a() (matrix or vector) to the value x. Abbreviation: m se a()=x MAT ONE a() generates from a square matrix a() a uniform matrix, i.e. a square matrix in which elements a(1,1),a(2,2),...,a(n.n) are all equally 1 and all other elements equally 0. Abbreviation: m o a() Example: DATA 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 DIM a(3,3) MAT READ a() PRINT a(1,1) MAT CLR a() PRINT a(1,1) Outputs the value 1, then 0. DIM a(5,7) FOR i%=1 TO 5 FOR j%=1 TO 7 a(i%,j%)=RAND(10) NEXT j% NEXT i% MAT SET a(),5.3 FOR i%=1 TO 5 FOR j%=1 TO 7 PRINT a(i%,j%) NEXT j% NEXT i% Outputs the value 3.5 35 times. DIM a(3,3) MAT ONE a() MAT PRINT a() Gives 1,0,0 0,1,0 0,0,1 Write and Read commands MAT READ a() MAT PRINT [#i]a[,g,n] MAT INPUT #i,a() i,g,n: iexp a: Name of field with numerical variables MAT READ a() reads a previously dimensioned matrix or vector from DATA rows. Abbreviation: m r a() Example: DATA 1,2,3,4,5,6,7,8,9,10 DIM a(2,5) MAT READ a() PRINT a(2,4) outputs the value 9. MAT PRINT [#i,]a()[,g,n] outputs a matrix or a vector. Vectors are output on one row, the elements being separated by commas. With matrix, each row is followed by a rowfeed. The output can optionally be redirected with #i, as with PRINT. If g and n are specified, the numbers are formatted as with STR$(x,g,n). Abbreviation: m p [#i]a()[g,n] or m ? [#i,]a()[g,n] Example: DATA 1,2.33333,3 DATA 7,5.25873,9.376 DATA 3.23,7.2,8.999 DIM a(3,3) MAT READ a() MAT PRINT a() PRINT"---------------" MAT PRINT a(),7,3 Gives: 1,2.33333,3 7,5.25873,9.376 3.23,7.2,8.999 --------------- 1.000,2.333,3.000 7.000,5.259,9.376 3.230,7.200,8.999 MAT INPUT #1,a() reads a matrix or vector from a file in ASCII format (the format being the reverse of MAT PRINT, commas and rowfeeds may be varied as with INPUT #). Abbreviation: m i #i,a(). Example: OPEN "o",#1,"Test.DAT" DIM a(3,3) MAT ONE a() MAT PRINT #1,a() CLOSE #1 MAT CLR a() OPEN "i",#1,"Test.DAT" MAT INPUT #1,a() CLOSE #1 MAT PRINT a() Gives: 1,0,0 0,1,0 0,0,1 Copy and Transposition commands MAT 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. Abbreviation: m c a(i,j)=b(k,l),h,w, m x a(i,j)=b(k,l),h,w, m t a()=b(). 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%)=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() Gives: 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 COPY 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 identi- cal indices are given in both the source and the destination matrix. Abbreviation: m c a()=b(). 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() Gives: 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 COPY 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. Abbreviation m c a(i,j)=b() 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() Gives: 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 COPY 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. Abbreviation: m c a()=b(i,j). 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() Gives: 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 COPY 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. Abbreviation: m c a(i,j)=b(k,l). 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() Gives: 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 COPY 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. Abbreviation: m c a()=b(). 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() Gives: 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. Abbreviation: m x a(i,j)=b(k,l),h,w. 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() Gives: 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() und 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() Gives: 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),b(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 PRINT a() Gives: 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() gibt 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()). Abbreviation: m t 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() Gives: 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 Operation commands MAT 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. Abbreviation: m a()=b()+c(). 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() Gives: 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. Abbreviation: m a a(),b(). 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() Gives: 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. Abbreviation: m a a(),x. Example: DIM a(3,5) MAT SET a()=1 MAT PRINT a() PRINT STRING$(10,"-") MAT ADD a(),5 MAT PRINT a() Gives: 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. Abbreviation: m a()=b()-c(). 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() Gives: 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,2,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. Abbreviation: m s a(),b(). 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() Gives: 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. Abbreviation: m s a(),x Example: DIM a(3,5) MAT SET a()=6 MAT PRINT a() PRINT STRING$(10,"-") MAT SUB a(),5 MAT PRINT a() Gives: 6,6,6,6,6 6,6,6,6,6 6,6,6,6,6 ---------- 5,5,5,5,5 5,5,5,5,5 5,5,5,5,5 ---------- 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. Abbreviation: m a()=b()*c() 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 Gives: 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 Gives: 1.0, 2.0, -3.0 ------------------ 4.0, 5.0, -1.0 ------------------ 4.0, 5.0, -1.0 8.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. Abbreviation: m x=a()*b(). 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 Gives: 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(). Abbreviation: m x=a()*b()*c(). 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 Gives: 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. Abbreviation: m no a(),0 bzw. m no a(),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 "zeilenweise normiert : " 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 "spaltenweise normiert : " PRINT MAT PRINT a(),7,2 ~INP(2) ' ' PRINT PRINT "Test : " PRINT FOR i%=1 TO 10 MAT CPY v()=a(1,i%) MAT MUL x=v()*v() PRINT x' NEXT i% ~INP(2) Gives: 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 zeilenweise normiert : 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 spaltenweise normiert : 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. Abbreviation: m d x=a([i,j])[,n]. 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 von a(1,4),4 : "; PRINT y PRINT PRINT "Test :" PRINT MAT CPY b()=a(1,4),4,4 ! kopiert die Teilmatix nach b() MAT PRINT b(),7,2 MAT DET z=b() ! berechnet die Determinant von b() PRINT PRINT z Gives: 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 optimised for speed rather than accuracy. Both will normally produce identical re- sults. With "critical" matrix, whose determinant is close to 0, you should always use MAT DET, though. Abbreviation: M qd x=a([i,j])[,n]. 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 Gives: 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. Abbreviation: m ra x=a([i,j])[,n]. 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 Gives: 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(). Abbreviation: m inv b()=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() = Einheitsmatrix ? " PRINT MAT MUL c()=b()*a() MAT PRINT c(),7,2 Gives: 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() = Einheitsmatrix ? 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 7. Further new commands in Version 3.5 In addition to the commands described in Chapter 6, Version 3.5 of GFA BASIC also implements three commands from the field of combinatorics, two commands for the operation of DATA pointers, Commands from the field of combinatorics These commands are: x=FACT(n) y=VARIAT(n,k) z=COMBIN(n,k) x,y,x: aexp n,k: iexp x=FACT(n) calculates the factorial (n!) of n and writes this value to the variable x. The factorial of an integer number is defined as the product of a multiplication with the first n integer numbers, with 0!=1. y=VARIAT(n,k) calculates the number of variations of n elements to the kth class without repetition, and writes this value to the variable y. The number of variations of n elements to the kth class without repetitions is defined as VARIAT(n,k)=n!/(n-k)! z=COMBIN(n,k) calculates the number of combinations of n elements to the kth class without repetitions and writes this value to the variable z. The number of combinations of n elements to the kth class without repetitions is defined as COMBIN(n,k) =n!/((n-k)!*k!) Example: x=FAXT(6) y=VARIAT(6,2) z=COMBIN(6,2) PRINT x,y,z ~INP(2) Gives: 720 30 15 Command for the operation of DATA pointers _DATA _DATA= _DATA specifies the position of the DATA pointer. _DATA is 0 if the next READ would result in an "out of data". _DATA= permits the setting of the DATA pointer to a value which has been previously determined with _DATA. Example: DIM dp%(100) DATA 1,2,3,4,5,6,7,8,9 DATA 13,24,328,3242,1,0 ' i%=0 DO WHILE _DATA dp%(i%)=_DATA INC i% READ a LOOP ' DEC i% ' FOR j%=i% DOWNTO 0 _DATA=dp%(j%) READ a PRINT a NEXT j% ~INP(2) Gives: 0 1 3242 328 24 13 9 8 7 6 5 4 3 2 1