home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
teach.zip
/
TEACH21A.ATF
< prev
next >
Wrap
Text File
|
1997-09-19
|
54KB
|
659 lines
XNÉIO 0 1 °
XNÉCT 0 1E²13 °
XCÉFC 1 6 .,*0_² °
XNÉRL 0 34075629 °
XCÉPR 1 1 °
XCÉLX 1 5 TEACH °
*(1996 4 6 16 11 29 328) °
FBIND ÉFX 'BIND' 'Σ Binding rules of APL2' °
''' 1. Brackets bind to the left''' °
''' 2. Left arrow binds to the left''' °
''' 3. Dyadic operator binds to the right''' °
''' 4. Strand notation binding''' °
''' 5. Operator binds to its left''' °
''' 6. Function binds to its left''' °
''' 7. Function binds to its right''' °
X ''' 8. Left arrow binds to its right'',r' °
*(1997 8 21 13 22 23 416) °
FCOSINES ÉFX 'u╜a COSINES w' 'ΣDD' °
X 'u╜²2Ω(a+.⌡φw)÷((+/a*2)°.⌡+/w*2)*0.5' °
*(1996 4 6 16 11 29 328) °
XFDEGREES ÉFX 'U╜DEGREES W' 'U╜180⌡W÷Ω1' °
*(1997 9 14 12 30 44 504) °
XFDISCLAIMER ÉFX 'DISCLAIMER' 'Σ Copyright statement' 'disclaimer' °
*(1996 4 6 16 11 29 328) °
FDISPLAY ÉFX 'D╜S DISPLAY A;ÉIO;R;C;HL;HC;HT;HB;VL;VB;V;W;N;B' °
'Σ DISPLAY A GENERAL ARRAY IN PICTORIAL FORM' °
'Σ NORMAL CALL IS MONADIC. DYADIC CALL USED ONLY IN' °
'Σ RECURSION TO SPECIFY DISPLAY RANK, SHAPE, AND DEPTH.' 'ÉIO╜0' °
'»(0=ÉNC ''S'')/''S╜µA''' 'R╜╞µ,S Σ PSEUDO RANK.' °
'C╜''┐┌└┘'' Σ UR, UL, LL, AND LR CORNERS.' °
'HL╜''─'' Σ HORIZONTAL LINE.' °
'HC╜HL,''Θ╕'',HL,''~+ε'' Σ HORIZONTAL BORDERS.' °
'HT╜HC[(0<R)⌡1+0<╞²1╞,S]' 'ΣW╜,0╧■╞0µΓ(1⌐µA)╞A' °
'HB╜HC[3+3╛(''2⌡~A╧«A'' ÉEA ''1+╞ε0⌡(1⌐⌡/µA)╞,A'')+3⌡1<µµS]' °
'VL╜''│'' Σ VERTICAL LINE.' °
'VB╜VL,''Φ╟'' Σ VERTICAL BORDER.' °
'V╜VB[(1<R)⌡1+0<²1╞²1╟,S]' °
'»(0εµA)/''A╜(1⌐µA)µΓ╞A'' Σ SHOW PROTOTYPE OF EMPTIES.' °
'╕(1<╧A)/GEN' '╕(2<µµA)/D3' °
'D╜«A Σ SIMPLE ARRAYS.' 'W╜1╞µD╜(²2╞1 1,µD)µD' °
'N╜²1+1╟µD' '╕(0=µµA)/SS' °
'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[ °
3]' '╕0' 'SS:HB╜((0 '' '')=╞0µΓA)/'' -''' °
'D╜'' '',('' '',[0]D,[0]HB,Nµ'' ''),'' ''' '╕0' °
'GEN:D╜«DISPLAY■A Σ ENCLOSED ...' 'N╜Dδ.⌠'' ''' °
'D╜(Nδ~1ΦN)≡D' 'D╜(δ≡~'' ''╤D)/D' 'D╜((1,µS)µS)DISPLAY D' °
'╕(2≥µ,S)╟D3E,0' 'D3:D╜0 ²1╟0 1╟«ΓA Σ MULT-DIMENSIONAL ...' °
'W╜1╞µD' 'N╜²1+1╟µD' °
'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[ °
3]' 'D3E:N╜²2+µ,S' °
X 'V╜C[Nµ1],[0]VB[1+0<²2╟,S],[0](((²3+╞µD),N)µVL),[0]C[Nµ2]' 'D╜V,D' °
*(1996 4 6 16 11 29 328) °
FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type: )OFF''' °
X '╕' °
*(1996 4 6 16 11 29 328) °
FGO ÉFX 'GO;T;E;B' 'Σ Expression driver' 'L0:B╜E╜''''' 'æ╜'' ''' °
'T╜æ' '╕(^/'' ''=T)/L0' '╕((^/'')OFF ''=5╞6╟T)doif ''EXIT'')/0' °
'╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/L0' °
'''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/L0' '╕B/L0' °
'''This is not a valid APL2 expression''' 'æ╜''*''' °
X '╕(''?''⌠╞1╟æ)/L0' 'E' '╕L0' °
*(1997 8 21 13 20 56 540) °
FHELP ÉFX 'HELP;N;I;T' 'Σ Help to student' '''WHAT TO DO'',r' °
''' ° To get out of the lesson''' ''' ENTER: EXIT''' °
''' ° To log off APL2''' °
''' FIRST, ENTER: EXIT THEN ENTER: )OFF''' °
''' ° To get help''' ''' ENTER: HELP''' °
''' ° When you see the prompt on a blank line''' °
''' ENTER AN APL2 EXPRESSION - OR JUST PRESS: ENTER''' 'do' °
''' ° If you get this line'',r' °
'''This is not a valid APL2 expression'',r,''*'',r' °
''' YOU CAN EITHER''' ''' A. PRESS: ENTER''' °
''' B. PRESS: ? and then ENTER to see what was incorrect''' °
''' in your expression causing that response'',r' 'do' °
'''HINTS'',r' °
'''This lesson is made up of '',(«N╜7),'' components named TEACHx, whe °
re''' '''the x stands for a digit:'',r' 'I╜0' °
'L0:T╜''TEACH'',(«I╜I+1)' 'T,'' '',1╟notb(ÉCR T)[2;]' '╕(N>I)/L0' °
'do' °
'''You may review either of these components separately. To do that,'' °
' °
'''first enter EXIT (and RETURN), then enter the name of the lesson.'' °
' '''component (e.g. TEACH4).'',r' °
'''To re-start the lesson, just enter TEACH'',r' °
'''When the screen fills up, it is a good idea to move the cursor to'' °
' '''the start of a convenient paragraph, and press ENTER'',r' °
'''You may also wish to press PAGE UP to review the prevous pages.''' °
'do' '''RESOURCES'',r' '''You may also enter the following word'',r' °
X '''BIND List of binding rules''' 'endd' °
*(1997 8 21 13 21 54 536) °
XFID ÉFX 'u╜ID w' 'ΣDD' 'u╜(2µw)µ1,wµ0' °
NIX 2 4 4 0.1844660194174758 ²0.002773925104022206 0.0915395284327323 °
²0.3079056865464632 0.07281553398058252 0.138002773925104 °
²0.05409153952843274 ²0.1816920943134535 ²0.03883495145631069 °
²0.1497919556171983 ²0.05686546463245491 0.3730929264909847 °
²0.1213592233009709 0.1033287101248266 0.09015256588072122 °
X ²0.03051317614424412 °
NIY 2 4 4 1.761904761904763 ²0.3333333333333336 ²0.9761904761904766 °
0.7142857142857147 ²5.714285714285718 1.000000000000001 °
3.071428571428573 ²1.857142857142859 4.523809523809526 °
²0.6666666666666673 ²2.452380952380954 1.42857142857143 °
²2.619047619047621 0.3333333333333337 1.761904761904763 °
X ²1.142857142857144 °
XNQ 2 3 3 162 179 153 179 262 194 153 194 214 °
*(1996 4 6 16 11 30 332) °
XFRADIANS ÉFX 'U╜RADIANS W' 'U╜ΩW÷180' °
*(1997 9 6 11 18 12 292) °
FTEACH ÉFX 'TEACH' 'Σ Start lesson #21: APL2 by Zdenek V JIZBA' °
'exit ''TEACH''' 'initialize' 'TEACH1 Σ Matrix algebra' °
'TEACH2 Σ Rotation matrix; vectors and vector length' °
'TEACH3 Σ Dot product' °
'TEACH4 Σ Introduction to matrix inverse; diagonal matrices' °
'TEACH5 Σ Grocery store example ; calculating matrix inverse' °
'TEACH6 Σ Properties of square matrices; positive definite' °
X 'TEACH7 Σ Domino applied to numeric vectors' 'problems' °
*(1997 7 22 12 3 51 448) °
FTEACH1 ÉFX 'TEACH1;T;X;Y' 'Σ Geometrical interpretation of matrices' °
'''In lesson 10 we studied elementary operations on numeric arrays''' °
'''called MATRICES. To refresh your memory, we learned that two''' °
'''numeric matrices can be added (or subtracted) provided their shape' °
'' '''is the same'',r' 'show ''É╜X╜2 3µ∞6'' ''É╜Y╜?2 3µ8'' ''X+Y''' °
'''A matrix can be added to (or multiplied by) a scalar'',r' °
'show ''X+0'' ''X⌡2'' ''X-5'' ''X÷2''' °
'''We also learned that two matrices can be multiplied, but the rules' °
'' '''of multiplication require that the last dimension of the left''' °
'''matrix be the same as the first dimension of the right matrix.'',r' °
'show ''X+.⌡φY'' ''(φX)+.⌡Y''' °
'''Also, the product is not COMMUTATIVE'',r' °
'show ''X+.⌡φY'' ''Y+.⌡φX''' °
'''Finally, we learned that there is a special matrix, called the''' °
'''IDENTITY MATRIX, that returns the original matrix unchanged by''' °
'''multiplication'',r' 'T╜ÉEX ''ID''' °
'1 show ''ID:(2µ∙)µ1,∙µ0'' ''ID 3'' ''X+.⌡ID 3'' ''(ID 2)+.⌡X''' °
'''Because of the properties just summarized above, it is possible to' °
'' °
'''develop an ALGEBRA based on matrices. We can, for example define''' °
'''matrix polynomials. We will define the SQUARE of a matrix as'',r' °
'show ''X+.⌡φX''' °
'''(To insure that dimensions will match, we have to use ID 2 3)''' °
'show ''ID 2 3'' ''5 + (-5⌡X+.⌡φID 2 3) + (X+.⌡φX)''' °
'''This would be roughly equivalent to polynomial Y╜5 + (-5X) + XX''' °
'''The only difference is that instead of scalars, X is a numeric matr °
ix.''' 'do' °
'''Actually most matrix polynomials deal with SQUARE matrices. In thes °
e,''' '''the number of rows and columns is the same'',r' °
'show ''X╜2 2µ∞4'' ''5 + (-5⌡X) + (X+.⌡φX)''' °
'''There are many practical applications of matrix algebra. Some of th °
e''' °
'''theoretical foundation of this field is treated in a very abstract' °
'' '''and general way. We will attempt to give a simple geometrical''' °
'''interpretation of some of these ideas. However, it should be pointe °
d''' °
'''out, that these simple geometrical representations cannot always be °
X''' '''extended to more general cases.''' 'endd' °
*(1997 7 22 12 17 40 460) °
FTEACH2 ÉFX 'TEACH2;R;V;X;Y;R3;R4' °
'Σ Rotation matrix, scaling and inversion' °
'''Consider the following 2⌡2 matrix'',r' °
'show ''É╜R╜2 2µ.6 ².8 .8 .6''' °
'''This matrix has the interesting property that its SQUARE is the''' °
'''UNIT matrix (we define ''''square'''' here as the expression R+.⌡φR °
)'',r' 'show ''R+.⌡φR''' °
'''The technical name for such a matrix is UNITARY, but we will call'' °
' °
'''it a ROTATION MATRIX. To explain why, consider the matrix product'' °
' '''(X+.⌡R). First we define X'',r' °
'show ''É╜X╜4 2µ6 8 5 0 1 3 6 ²2'' ''É╜Y╜X+.⌡R''' °
'''We end up with another numeric array Y. What we want to know is wha °
t''' '''does this new array mean?''' 'do' 'show ''X+.⌡φX'' ''Y+.⌡φY''' °
'''For one, the square of both X and Y are the same. This means that'' °
' °
'''the values in Y remain in the same relationship to each other as''' °
'''in the original matrix X. If you treat the rows of X as points to b °
e''' °
'''plotted on a cartesian graph, then it is easy to explain the effect °
''' °
'''of matrix R. When the rows of Y are plotted on the same graph, the' °
'' °
'''new points have been moved as if rotated on an axis perpendicular t °
o''' °
'''the plane of the plot, and passing through the origin of the graph. °
''' 'do' °
'''In fact, the rotation is counter clockwise, and the cosine of the'' °
' '''angle is'',r' 'show ''²3Ω÷/ΦR[1;]''' °
'''Just to verify that this INVARIANCE applies to matrices of any size °
,''' '''let us try some more examples'',r' °
'show ''É╜R3╜3 3µ.01⌡64 ²60 ²48 48 80 ²36 60 0 80''' °
'''R3 is a three dimensional rotation matrix'',r' °
'show ''15«R3+.⌡φR3'' ''É╜X╜3 3µ4 8 ²4 5 15 16 ²3 ²6 13'' ''É╜Y╜X+.⌡R3 °
''' '''The squares X+.⌡φX and Y+.⌡φY should be the same'',r' °
'show ''X+.⌡φX'' ''Y+.⌡φY''' °
'''We can also try a four dimensional unitary matrix'',r' °
'R4╜4 4µ0.01⌡64 ²48 ²36 ²48 48 64 48 ²36 ²36 ²48 64 ²48 48 ²36 48 64' °
'X╜3 4µ18 1 19 8 4 8 ²4 7 2 ²6 ²5 10' °
'show ''R4'' ''15«R4+.⌡φR4'' ''X'' ''É╜Y╜X+.⌡R4'' ''X+.⌡φX'' ''Y+.⌡φY' °
'' '''WORKING WITH VECTORS'',r' °
'''To better understand what these numeric manipulations mean, it is'' °
' °
'''useful to discuss the concept of VECTORS. Consider the point V2 on' °
'' '''the following graph'',r' 'vec ''X'' ''V2'' ''Y''' °
'''The directed line starting at the origin and ending at point V2 is' °
'' °
'''called a VECTOR. It''''s coordinates are 2 2, and its length by the °
''' °
'''theorem of Pythagoras is 8*.5 (or 2⌡2*2). Suppose now that we add'' °
' °
'''another number to vector V2╜2 2, say another 2 (V3╜2 2 2). Then we' °
'' °
'''can display the vector V2 against this new value. (We shall call th °
is''' '''new coordinate Z)''' 'do' '''..⌡'' vec ''V2'' ''V3'' ''Z''' °
'''By theorem of Pythagoras, the length of vector V3 is ((V2*2)+2*2)*. °
5''' °
'''or 12*.5 (or 3⌡2*2). We can add yet more elements to the vector. Ea °
ch''' °
'''time the length of the new vector can be found by adding the square °
''' °
'''of the new coordinate to the sum of squares of the preceeding ones, °
''' '''and taking the square root of the sum.''' 'do' °
'''In other words, given vector V'',r' 'show ''V╜?5µ10'' ''V''' °
'''the expressions'',r' 'show ''(+/V*2)*.5'' ''(V+.⌡φV)*.5''' °
'''return the length of vector V, NO MATTER HOW MANY ELEMENTS V has!'' °
' °
'''Note that the expression V+.⌡φV produces the same result as +/V*2.' °
'' °
'''There is a good reason for this expression as we will see next.''' °
X 'endd' °
*(1997 7 22 12 21 37 464) °
FTEACH3 ÉFX 'TEACH3;A;B;T;X;Y;Va;Vb;LX;LY;R3' 'Σ Dot product' °
'''DOT PRODUCT'',r' °
'''Consider two vectors Va and Vb. We can ask for the meanimg of the'' °
' '''expression Va+.⌡φVb'',r' 'show ''(Va╜2 4 6 3)+.⌡φVb╜1 5 7 2''' °
'''This expression is known as the DOT PRODUCT. Recalling that rotatio °
n''' °
'''does not change the result, we can align Va with the X axis, and pl °
ace''' '''Vb in the X,Y plane'',r' °
'''...|.⌡Va'' vec '' X'' ''Vb'' ''Y''' 'do' °
'''In this orientation, the X component of Va is the length of Va. The °
''' °
'''components of Va in all other dimensions are zero. The X component' °
'' °
'''of Vb along the X axis is Vb⌡2Ωα, where α is the angle between the' °
'' °
'''two vectors. It follows therefore that the expression Va+.⌡φVb give °
s''' °
'''the product of the lengths of the two vectors times the COSINE of t °
he''' '''angle between them.''' 'do' °
'''In the above example, we have'',r' °
'show ''É╜A╜(+/Va*2)*.5'' ''É╜B╜(+/Vb*2)*.5''' °
'''Even though the two vectors have four components (four dimensions), °
''' °
'''we can readily calculate the angle between them. First we define'', °
r' 'T╜ÉEX ''COSINES''' °
'1 show ''COSINES:²2Ω(α+.⌡φ∙)÷((+/α*2)°.⌡+/∙*2)*.5''' °
'show ''DEGREES Va COSINES Vb''' °
'''With this knowledge, we can now explain the geometric meaning of''' °
'''a rotation matrix'',r' 'R3╜3 3µ0.01⌡64 ²60 ²48 48 80 ²36 60 0 80' °
'show ''R3'' ''+/R3*2'' ''15«R3+.⌡φR3''' °
'''The second expression shows that the vectors of a rotation matrix'' °
' °
'''have length 1. The last expression shows that the three vectors are °
''' °
'''at right angles to each other, since the COS of 90 degrees is zero. °
''' 'do' °
'''Finally, we can also explain why rotation does not change the resul °
t''' '''of expression X+.⌡φX where X is a numeric array'',r' °
'X╜3 4µ18 1 19 8 4 8 ²4 7 2 ²6 ²5 10' °
'Y╜3 4µ9 ²20 10 ²13 11.2 2.6 3.2 1.6 5 ²6 ²2 10' °
'''In our previous example we had'',r' °
'show ''X'' ''X+.⌡φX'' ''Y'' ''Y+.⌡φY''' °
'''We can verify that the vectors (rows) of X have the same length as' °
'' '''the rows of Y'',r' °
'show ''É╜LX╜(+/X*2)*.5'' ''É╜LY╜(+/Y*2)*.5''' °
'''And the angles between each pair of these vectors is the same'',r' °
X 'show ''DEGREES X COSINES X'' ''DEGREES Y COSINES Y''' 'endd' °
*(1997 7 22 12 28 36 488) °
FTEACH4 ÉFX 'TEACH4;R3;C;D;R;S;X;Y;DI' 'Σ The inverse of a matrix' °
'''THE MATRIX INVERSE'',r' °
'''It is not our intention here to give a lecture on matrix algebra.'' °
' °
'''Actually we are leading towards the introduction of an important''' °
'''primitive function of APL2 called the MATRIX INVERSE. If this''' °
'''function is to make any sense at all, some elementary concepts''' °
'''such as those discussed above are useful. Before we introduce the'' °
' °
'''inverse, we have to describe yet another type of matrix, called''' °
'''a DIAGONAL matrix'',r' 'R3╜3 3µ0.01⌡64 ²60 ²48 48 80 ²36 60 0 80' °
'show ''É╜D╜3 3µ2 5 4'' ''1 1φD''' °
'''(You will recall from lesson 8 that the expression 1 1φ extracts th °
e''' '''diagonal elements of an array of rank 2.)'',r' °
'show ''D╜D⌡ID 3'' ''D''' °
'''One way to form a diagonal matrix is to first generate one that''' °
'''has the desired values in the diagonal as illustrated by the first' °
'' °
'''expression. Simple multiplication of this matrix by the identity''' °
'''matrix sets all of-diagonal values to zero.''' 'do' °
'''To see what effect a diagonal matrix has, we do a matrix product wi °
th''' '''the rotation matrix R3'',r' 'show ''R3'' ''É╜R╜D+.⌡R3''' °
'''The rows of this product matrix have been multiplied by the values' °
'' '''in the diagonal (2 5 4). To multiply the columns, we write'',r' °
'show ''É╜C╜R3+.⌡D''' °
'''Suppose now that we desire to reverse the process. What we need is' °
'' °
'''to be able to divide the rows and columns by the elements of the''' °
'''diagonal. One way to do that is to generate another diagonal matrix °
''' '''with elements that are reciprocals of the values in D'',r' °
'show ''É╜DI╜(ID 3)⌡3 3µ÷2 5 4'' ''C+.⌡DI'' ''DI+.⌡R''' °
'''Actually, there is a simpler way to find DI, the INVERSE of D'',r' °
'show ''ÆD''' °
'''The symbol Æ (press Alt and ⌡) is called the DOMINO. When used''' °
'''monadically it generates a matrix INVERSE. Basically, the inverse'' °
' '''can be thought of as a generalization of the divide symbol ÷'',r' °
'show ''÷2 5'' ''Æ■2 5''' °
'''and as the example above shows, will produce the same results when' °
'' °
'''applied to numeric scalars. However for the same reason that we get °
''' '''a DOMAIN ERROR with'',r' 'show ''÷2 4 0''' °
'''there are some special matrices (called SINGULAR) that also have''' °
'''no inverse'',r' 'show ''É╜S╜(ID 3)⌡3 3µ2 4 0'' ''ÆS''' °
'''What effect does matrix product with a diagonal matrix have? It''' °
'''can be thought of as re-scaling of the axes'',r' °
'show ''15«R3+.⌡φR3'' ''R+.⌡φR''' °
'''The components of R no longer have unit lengths. If the vectors for °
ming''' °
'''a matrix are not orthogonal, then a product with the diagonal also' °
'' '''changes the angles'',r' °
'show ''É╜X╜2 3µ4 8 ²4 5 15 16'' ''Y╜X+.⌡D'' ''X COSINES X'' ''Y COSIN °
XES Y''' 'endd' °
*(1997 7 22 12 36 28 488) °
FTEACH5 ÉFX 'TEACH5;L;INB;BUY;PRICE;COST' 'Σ Solving linear equations' °
'''Naturally, there is more to the inverse than just taking the recipr °
ocals''' °
'''of a diagonal matrix. To illustrate a general case of matrix invers °
e,''' '''we will use the following example:'',r' °
'''Suppose that a grocery store sells certain fruit by the piece: an a °
pple''' °
'''for 30 cents, an orange for 40 cents, and a banana for 50 cents. On °
e''' °
'''customer buys two apples one orange and one banana, and pays $1.50' °
'' °
'''While a second customer pays $2.10 for one apple, two oranges and'' °
' °
'''two bananas. A third customer is charged $2.20 for three apples,''' °
'''two oranges and one banana.''' 'do' °
'''We can readily calculate the tab for each customer using matrix''' °
'''multiplication. To do that, we define a matrix BUY, with rows''' °
'''corresponding to customers, and columns corresponding to the items' °
'' '''being purchased'',r' 'show ''É╜BUY╜3 3µ2 1 1 1 2 2 3 2 1''' °
'''We also have the array PRICE for the cost of individual items'',r' °
'show ''É╜PRICE╜0.30 0.40 0.50''' °
'''To find out how much each customer has to pay, we multiply BUY by'' °
' '''PRICE to get COST'',r' 'show ''É╜COST╜BUY+.⌡PRICE''' °
'''But now suppose we forgot the values in PRICE. Can we recover this' °
'' °
'''information from BUY and COST? The answer is yes. One way is to''' °
'''find the INVERSE of BUY'',r' °
'show ''INB╜ÆBUY'' ''('''' $0.59'''')«INB+.⌡COST''' °
'''The process of generating the inverse is a fairly simple procedure' °
'' °
'''There are many algorithms to do it, but the fastest one still takes °
''' °
'''N*3 times, so it is a cubic algorithm. Here is an example of how''' °
'''you might do it with a pencil and paper. Given'',r' 'show ''BUY''' °
'''we want to calculate'',r' 'show ''ÆBUY''' °
'''We begin by catenating BUY with ID 3''' 'show ''É╜L╜BUY,ID 3''' °
'''We follow these two rules:'',r' °
''' 1. Any row can be multiplied by a constant''' °
''' 2. Any row can be replaced by adding another row to it'',r' °
'''With these two rules, we try to convert the first three columns''' °
'''to an identity (diagonal) matrix. We begin by adding ²1 times the'' °
' °
'''third row to the first row. Our plan of action is to first set the' °
'' °
'''upper off diagonals to zero. Then we set the lower off diagonals to °
''' '''zero, and finally we set the diagonal values to one'',r' °
'show ''L[1;]╜-≡L[1 3;]'' ''L''' 'show ''L[2;]╜L[2;]-2⌡L[3;]'' ''L''' °
'show ''L[1;]╜-L[2;]-2⌡L[1;]'' ''L''' °
'show ''L[2;]╜(5⌡L[1;])+3⌡L[2;]'' ''L''' °
'show ''L[3;]╜-≡L[1 3;]'' ''L''' 'show ''L[3;]╜L[2;]-3⌡L[3;]'' ''L''' °
'show ''L╜L÷3'' ''L''' °
'show ''L[2;]╜L[2;]÷²2'' ''L'' ''0 3╟L'' ''INB''' °
'''The example we have used to illustrate the usage of matrix inverse' °
'' °
'''is actually best solved using the dyadic form of the domino functio °
Xn.''' '''We will study that in the next lesson.''' 'endd' °
*(1997 7 23 13 29 8 388) °
FTEACH6 ÉFX 'TEACH6;R4' 'Σ Properties of the inverse' °
''' PROPERTIES OF THE MATRIX INVERSE'',r' °
'''We will finish this lesson with a brief summary of the more''' °
'''important relationships in matrix algebra.'',r' °
'''We have already seen that matrix multiplication is not commutative. °
''' °
'''This word means that for any two numeric arrays X and Y, the inner' °
'' '''products X+.⌡Y and Y+.⌡X are not the same'',r' °
'show ''É╜X╜?3 4µ10'' ''É╜Y╜?4 3µ10'' ''X+.⌡Y'' ''Y+.⌡X''' °
'''The two products do not even have the same dimensions. Their diagon °
als,''' '''however, have the same sum'',r' °
'show ''+/1 1φX+.⌡Y ╪ +/1 1 φY+.⌡X''' °
'''When both X and Y are square and of the same size, we can say a lot °
''' '''more about their product'',r' °
'show ''É╜X╜?4 4µ10'' ''É╜Y╜?4 4µ10''' °
'''The two ways of forming the inner product can be related'',r' °
'show ''φX+.⌡Y'' ''(φY)+.⌡φX''' °
'''The rule that applies here can be phrased as follows: THE TRANSPOSE °
''' °
'''OF A PRODUCT IS THE SAME AS THE PRODUCT OF THE TRANSPOSES IN REVERS °
E''' '''ORDER.'',r' 'do' °
'''The inverse of a matrix exists only for a special kind of square''' °
'''matrices called NON-SINGULAR. (The odds are that both X and Y are'' °
' '''non singular. If in the following expressions you get a DOMAIN''' °
'''ERROR, re-define X [or Y] and try again.) We form the inverses of'' °
' '''X and Y'',r' 'show ''IX╜ÆX'' ''IY╜ÆY''' °
'''First let us see the products of X and IX'',r' °
'show ''X+.⌡IX'' ''IX+.⌡X''' °
'''Both products return the identity matrix accurate to at least 15''' °
'''significant digits. This should be no surprise, since the transpose °
''' °
'''of the identity matrix is also the identity matrix. But now let us' °
'' '''try to invert the product of X and Y''' 'do' °
'show ''ÆX+.⌡Y'' ''IY+.⌡IX''' °
'''This is very analogous to the transpose of of a product. Indeed we' °
'' °
'''have the following rule: THE INVERSE OF A PRODUCT IS THE SAME AS TH °
E''' '''PRODUCT OF THE INVERSES IN REVERSE ORDER.''' 'do' °
'''Now what about UNITARY (rotation matrices)? Consider R4'',r' °
'R4╜4 4µ0.01⌡64 ²48 ²36 ²48 48 64 48 ²36 ²36 ²48 64 ²48 48 ²36 48 64' °
'show ''R4'' ''R4+.⌡φR4'' ''R4+.⌡ÆR4''' °
'''Since both the transpose and the inverse produce the same identity' °
'' '''matrix, it follows that the two are the same'',r' °
'show ''(φR4)╧ÆR4''' °
'''Finally, we should make a remark about the product of a matrix''' °
'''(not necesarily square) with its own transpose. Before we do that'' °
' '''consider the following polynomial'',r' °
''' (X+Y)*2 ╜ ╕ (X*2) + (2⌡X⌡Y) + Y*2''' 'do' °
'''We can write this in the form of an array'',r' °
''' X*2 X⌡Y''' ''' X⌡Y Y*2'',r' °
'''We can even generalize this'',r' °
''' (X+Y+Z)*2 ╜ ╕ (X*2) + (Y*2) + (Z*2) + (2⌡X⌡Y) + (2⌡X⌡Z) + 2⌡Y⌡Z'', °
r' '''and in tabular form'',r' ''' X*2 X⌡Y X⌡Z''' °
''' X⌡Y Y*2 Y⌡Z''' ''' X⌡Z Y⌡Z Z*2'',r' °
'''Now, when we define X as''' 'do' 'show ''É╜X╜?3 5µ10''' °
'''We can think of each row as a VECTOR. The product X+.⌡φX therefore' °
'' °
'''represents a DOT product of each vector with every other vector.'', °
r' 'show ''É╜Q╜X+.⌡φX''' °
'''The diagonals contain the SUM OF SQUARES of the vectors of X, and t °
he''' °
'''off diagonals are the dot products of vector pairs. Because of the' °
'' °
'''analogy with squares of polynomials (actually it is more than that) °
''' °
'''the resuting array has a special name. It is called a QUADRATIC FOR °
M.''' °
'''The matrix Q also has many interesting, and computationally importa °
nt''' °
'''properties. It is often referred to by one of its properties, namel °
Xy''' '''a POSITIVE DEFINITE matrix.''' 'endd' °
*(1997 7 23 13 33 34 508) °
FTEACH7 ÉFX 'TEACH7' 'Σ Domino with vectors' °
'''VECTOR ARGUMENT TO DOMINO'',r' °
'''Finally, if the domino is applied to a vector, the result will''' °
'''be another vector'',r' 'show ''É╜V2╜ÆV1╜2 3 4''' °
'''The dot product of these two vectors is 1'',r' 'show ''V1+.⌡V2''' °
X 'endd' °
*(1996 4 6 16 11 30 332) °
FTIME ÉFX 'U╜V TIME W;T' 'Σ Measure execution time of W' °
X 'U╜60 60 1000¥²3╞ÉTS' 'T╜»■VµΓW' 'U╜(,-U-60 60 1000¥²3╞ÉTS)÷V' °
XNV1 1 3 2 3 4 °
XNV2 1 3 0.06896551724137931 0.103448275862069 0.1379310344827586 °
XNX 2 3 5 10 1 6 4 3 10 6 5 10 1 8 8 9 2 1 °
XNY 2 4 4 3 3 4 2 5 9 10 1 10 6 6 4 10 5 3 1 °
*(1997 7 13 12 28 49 504) °
Faddquote ÉFX 'u╜addquote w' °
'Σ Put quotes around a string, and double existing quotes' °
X 'u╜ÉAV[40],((1+w=ÉAV[40])/w),ÉAV[40]' °
*(1996 4 6 16 11 30 332) °
XFaq ÉFX 'U╜aq W' 'U╜Γaddquote W' °
*(1997 7 24 13 20 38 476) °
Fav ÉFX 'av;A;N;I;ÉIO' 'Σ Display characters in ÉAV' 'ÉIO╜0' °
'A╜22 78µ'' ''' 'N╜3 0«φ12 22µ1+∞356' 'A[;,(6⌡∞12)°.+2 3 4]╜N' °
'A[;6+6⌡∞12]╜φ12 22µÉAV' 'ΣA[8 10 13;6]╜'' ''' 'A[13;6]╜'' ''' °
X 'A[14+∞8;68 69 70 72]╜'' ''' 'A' °
*(1991 11 11 8 25 13 316) °
Fdate ÉFX 'u╜date w' 'Σ Format date and time of day' 'u╜«6╞w' °
X 'u╜('' ''⌠u)Γu' 'u╜εu,■''-- .. ''' °
XCdig 1 10 1234567890 °
*(1997 9 9 13 0 45 372) °
Fdisclaimer ÉFX 'disclaimer' 'Σ Copyright statement' °
'(10µ'' ''),''Copyright, Z. V. Jizba, 1995,1996,1997'',r' °
''' This and subsequent workspaces labelled TEACHxx are made available °
''' °
'''at no cost to anyone who desires to learn how to use effectively''' °
'''the IBM/OS2 version of APL2.'',r' °
'''This software is provided "AS IS" with no WARRANTY of any kind, eit °
her''' °
'''express or implied. Any risk in its use resides with you, the user °
of''' '''these tutorials.'',r' ''' ACKNOWLEDGEMENTS'',r' °
''' In writing these tutorials, I am greatly indebted to Roy Sykes, wh °
ose''' °
'''excellent lectures increased my understanding of the language.''' °
'''Discussions with the late Harry Bertucelli clarified a number of''' °
'''concepts and caused me to change some improper terminology that was °
''' °
'''used in previous versions of these tutorials. Mr. Benjamin Archer'' °
' °
'''kindly checked out a nearly final version, bringing to my attention °
''' '''some ommisions, misspellings, and invalid terminology.'',r' °
X '''(PRESS ENTER to continue)''' °
*(1997 7 13 12 28 50 508) °
Fdo ÉFX 'do;T;E' 'Σ Expression driver' 'E╜''''' 'æ╜'' ''' 'T╜æ' °
'╕(^/'' ''=T)/0' °
'╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/2' °
'''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/2' °
'''This is not a valid APL2 expression''' 'æ╜''*''' '╕(''?''⌠╞1╟æ)/2' °
X 'E' '╕2' °
*(1997 7 13 12 28 50 508) °
Fdoif ÉFX 'U╢╜V╢ doif W╢;t╢' 'Σ Rule' '╕(^/~U╢╜V╢)/0' °
X '''U╢╜V╢ doif■ W╢'' ÉEA ''»V╢/W╢''' °
*(1997 9 9 12 50 14 444) °
Fendd ÉFX 'endd' 'Σ end of special feature' '20µ''²'' ╪ ╕(4<µÉLC)/0' °
X 'do' °
*(1997 8 21 13 16 53 512) °
Ferase ÉFX °
'erase;t;EXIT;GO;HELP;DISPLAY;BIND;TIME;ID;DEGREES;RADIANS;COSINES;DIS °
CLAIMER' 'Σ Erase all global functions and variables' 't╜ÉNL 3' °
't╜(~t^.εlc,'' '')≡t' 't╜ÉEX(~t[;∞5]^.=''TEACH'')≡t' 't╜ÉNL 2' °
X 't╜ÉEX(~t^.εlc,'' '')≡t' 't╜ÉNL 4' 't╜ÉEX(~t^.εlc,'' '')≡t' °
*(1997 7 27 13 47 41 608) °
Fevaldd ÉFX 'u╜evaldd w;c;n' 'Σ Evaluate direct definition' 'u╜0' °
'n╜(w∞''Σ'')-1' 'c╜(((n╞w)⌠'':'')Γn╞w),Γ''ΣDD '',(n+1)╟w' °
'╕((1 label╞c)doif ''''''Invalid label'''''')/0' °
'╕((2=µc)doif ''u╜showdd 1╙c'')/0' °
'╕((3=ÉNC╞c)doif ''u╜⌡µÉ╜(╞c),'''' is already defined.'''''')/0' °
'╕((3=µc)doif ''u╜simdd c'')/0' 'c╜(Γ''α∙ aw'')replace■c' °
'u╜ε''u╜'',((''a''εεc[2 3 4])/''a ''),(╞c),'' w;t;b''' °
'u╜u(5πc)(''b╜(t╜'',(3πc),'')/'',addquote ''u╜'',4πc)' °
X 'u╜u,''╕(t doif b)/0''(''u╜'',2πc)' 'u╜╧ÉFX u' °
*(1997 7 25 13 27 52 564) °
Fexit ÉFX 'V exit W;T' 'Σ Exit if too many suspended functions' °
'╕(0⌠ÉNC ''V'')/L0 ╪ V╜10' 'L0:╕(V>µÉLC)/0' °
'''There are too many suspended functions''' '''Please enter '',W' °
X '╕' °
*(1997 7 26 12 33 39 536) °
Fget ÉFX 'U╜V get W;t;T;ÉPR' 'Σ Prompt for response from keyboard' °
'ÉPR╜T╜ÉAV[ÉIO+255] ╪ ╕(0⌠ÉNC ''V'')/L0 ╪ V╜1' 'L0:V╜V╧1' 'æ╜W ╪ t╜æ' °
'U╜(+/^\t=T)╟t' '╕(''╕''⌠╞U)/L1 ╪ ╕' 'L1:╕V/0' 't╜(U⌠'' '')ΓU' °
X 'U╜(µt),(ΓU),t' °
*(1997 7 28 13 33 8 424) °
Fglobals ÉFX 'globals' 'Σ Initialize useful global variables' °
'uc╜''ABCDEFGHIJKLMNOPQRSTUVWXYZ''' °
'lc╜''abcdefghijklmnopqrstuvwxyz''' 'dig╜''1234567890''' °
X 'r╜ÉAV[13+ÉIO]' 'q╜''''''''' °
*(1997 7 3 12 47 6 368) °
Finitialize ÉFX 'initialize;T' 'Σ Initialize workspace' °
'''AT ALL TIMES, TO CONTINUE, PRESS RETURN!'',r' °
'''To see disclaimers enter:'',r,'' disclaimer''' 'do' 'erase' °
'globals' °
'''Make sure the CAP LOCK light on your keyboard (upper right) is ON!' °
X'' 'endd' °
*(1997 7 27 13 14 33 444) °
Flabel ÉFX 'u╜v label w' °
'Σ Return 1 if label w does not begin with a cap' °
'╕(0⌠ÉNC ''v'')/L0 ╪ v╜0' 'L0:v╜v╧1 ╪ w╜εw ╪ ╕v/L1 ╪ ╕(u╜0⌠ÉNC w)/0' °
X 'L1:╕(u╜~^/wεlc,uc,dig)/0' 'u╜w[1]εlc,dig' °
XClc 1 26 abcdefghijklmnopqrstuvwxyz °
*(1997 7 13 12 28 55 528) °
Fnon ÉFX 'non;T;RC;ET;R' 'Σ Ignore keyboard entry' 'æ╜'' ''' 'T╜æ' °
'╕(0=µ(T⌠'' '')/T)/0' '(RC ET R)╜ÉEC T' '╕(0=RC)/2' °
X '╕((1=RC)doif ''R'')/2' '╕2' °
*(1997 7 13 12 28 55 528) °
Fnotb ÉFX 'u╜notb w' 'Σ Remove trailing blanks' °
'╕((1<╧w)doif ''u╜notb■ w'')/0' '╕((1<µµw)doif ''u╜πnotb Γ[2]w'')/0' °
X 'u╜(1-(,'' ''⌠Φw)∞1)╟w' °
*(1996 4 6 16 11 30 332) °
Fpause ÉFX 'V pause W;T' °
'Σ Pause, then print W V spaces right and return' °
X 'T╜(0=ÉNC ''V'')doif ''V╜6''' 'do' '(Vµ'' ''),W' 'do' °
*(1997 7 27 12 55 6 496) °
Fproblems ÉFX 'problems' 'Σ Problems' °
'''That is all for this lesson. Remember, if you want to practice,''' °
'''and plan to use direct definitions, be sure to first enter GO.''' °
'''Direct definitions will then be accepted. To exit GO, enter EXIT.'' °
,r' °
'''To erase a previously defined DIRECT DEFINITION FUNCTION, enter'',r °
' ''' )ERASE functionname'',r' °
X '''WARNING! do not use )ERASE on other labels.'',r' °
XCq 0 ' °
XCr 0 °
*(1997 7 13 12 28 56 532) °
Freplace ÉFX 'u╜v replace u;i;r;s' 'Σ Replace elements in v in u' °
'i╜Γ∞µu' 's╜2πv╜(v⌠'' '')Γv' 'i╜⌡r╜i⌡■Γ[1]u°.=╞v' °
X 'u[(εi)/εr]╜s[(εi)/εi⌡■∞µs]' °
*(1997 7 13 12 28 56 532) °
Fround ÉFX 'U╜V round W' 'Σ Half adjust to V th decimal' °
X 'U╜(╛0.5+W⌡10*V)÷10*V' °
*(1997 7 13 12 28 57 536) °
Fshow ÉFX '╢V show ╢W;╢T;╢B' 'Σ Display and execute ╢W' °
'╢T╜(0=ÉNC ''╢V'')doif ''╢V╜0''' °
'╕((0=╧╢W)doif ''show ╢W,'''' '''''')/0' °
'╕((1<╧╢W)doif ''╢V show ■╢W'')/0' ''' '',╢W' °
X '╕((╢V^'':''ε╢W)doif ''╢T╜evaldd ╢W'')/L0' '''ÉEM'' ÉEA ╢W' 'L0:do' °
*(1997 7 13 12 28 57 536) °
Fshowdd ÉFX 'u╜showdd w;a;b;c;r' °
'Σ Display a direct definition function' °
'╕((1=╧w)doif ''u╜showdd Γw'')/u╜0' °
'╕((3⌠ÉNC╞w)doif ''(ε╞w),'''' is not a function'''''')/0' °
'c╜Γ[2]ÉCR╞w' 'c╜notb(2╞c),(Γ''aw α∙'')replace■2╟c' °
'╕((~''ΣDD''╧3╞2πc)doif ''''''Not a direct definition function'''''')/ °
0' 'u╜1' 'b╜('' ''⌠╞c)Γ╞c' 'a╜'' ''' 'r╜2╟3πc' °
'╕((3=µc)doif ''a,(╞w),'''':'''',r,(3<µ2πc)/'''' Σ'''',3╟2πc'')/0' °
'a╜a,(╞w),'':'',(2╟5πc),'':''' 'b╜(+\r=''('')-+\r='')''' 'b╜b∞0' °
X 'a╜a,(²3╟(b-1)╞3╟r),'':'',2╟»(b+2)╟r' 'a,(3<µ2πc)/'' Σ'',3╟2πc' °
*(1997 7 13 12 28 57 536) °
Fshowfn ÉFX 'U╜V showfn W;F;N;T;ÉIO' 'Σ Simulate ╖W[É]' °
'T╜(0=ÉNC ''V'')doif ''V╜0''' 'ÉIO╜0' °
'U╜r,'' '',''╖'',W,''[É]'',(╞V)╞''╖''' 'N╜1╞µF╜ÉCR W' 'N╜«∞N' °
'N╜(N⌠'' '')ΓN' 'F╜(π''['',■N,■Γ''] ''),F' °
'T╜(1<µ,V)doif ''F╜F[1╟V;]'' ''U╜''''''''''' 'U╜²1╟U,r,,F,r' °
X 'U╜((-+/^\'' ''=ΦU)╟U),('' ╖'')[╞V],r' °
*(1997 7 13 12 28 58 540) °
Fsimdd ÉFX 'u╜simdd w;e' 'Σ Direct definition mode' 'u╜0' °
'╕((0⌠ÉNC╞w)doif ''''''Already defined'''''')/0' 'e╜''α''ε2πw' °
'w[2]╜Γ''u╜'',''α∙ aw'' replace 2πw' 'w╜w[1 3 2]' °
X 'w[1]╜Γε''u╜'',(e/''a ''),w[1],'' w''' 'u╜╧ÉFX w' °
*(1992 6 3 9 59 17 424) °
Ftab ÉFX 'U╜V tab W;T;A;B;C;D;E;F;G;M;ÉPW' 'Σ Tabulate list W' °
'T╜(0=ÉNC ''V'')doif ''V╜0''' 'M╜''Invalid data for tabulation''' °
'V╜4╞V' 'ÉPW╜130╛30⌐G╜V[2]+79⌡V[2]=0' °
'L1:╕((1<╧W)doif ''''''W╜∞0'''' ÉEA ''''W╜πW'''''')/L1' °
'╕(((0=µεW)δ2<µµW)doif ''U╜(~V╧4╞0)/M'')/0' °
'T╜(1≥µµU╜«W)doif ''U╜πW╜(U⌠'''' '''')ΓU''' °
'T╜(0<V[1])doif ''U╜(«(Φ1,╞µW)µ(V[3]µ'''' ''''),∞(╞µW)-V[3]),'''' '''' °
,U''' '╕(G<30)/0' 'T╜(F╜µεV[4])+C╜1╟B╜µA╜(V[3],0)╟U' °
'T╜⌐(1╞B)÷1⌐╛(ÉPW+F)÷T' 'U╜(E╜(V[3],C)╞U),[1](B╜T,1╟B)╞A' °
'''D╜εV[4]'' ÉEA ''D╜ÉAV[εV[4]+33⌡V[4]=0]''' 'L0:A╜(T,0)╟A' °
X '╕(0=1╞µA)/0' 'U╜U,(((T+V[3]),µD)µD),E,[1]B╞A' '╕L0' °
*(1997 7 13 12 28 59 544) °
Ftest ÉFX 'U╜V test W;P' °
'Σ Describe problem in W, (correct answer in V)' 'U╜2' 'L1:W' °
'É╜'' ''' 'P╜æ' '''╕L0'' ÉEA ''P╜»P''' '╕(V╧P)/0' °
X 'L0:╕(0=U╜U-1)/0' '''Incorrect. Try again''' '╕L1' °
XCuc 1 26 ABCDEFGHIJKLMNOPQRSTUVWXYZ °
*(1997 8 21 13 15 13 348) °
Fupdate ÉFX 'update' °
'''This version of APL2 lessons has been updated in the summer of 1997 °
''' °
'''Any subsequent updates will be announced to the APL news group.''' °
'''You may also e-mail me at jizba@kaiwan.com for additional details.' °
'' '''Any constructive comments will be welcome.'',r' °
'''For an update of these lessons, mail a self addressed stamped''' °
'''floppy disk mailer with two HD 3.5 inch blank floppies to:'',r' °
''' Zdenek V. Jizba''' °
''' 1341 Rebecca Dr.''' °
X ''' La Habra, CA 90631''' °
*(1996 4 6 16 11 30 332) °
Fvec ÉFX 'U╜V vec W;T' 'Σ Draw 2d vector in plane' °
'T╜(0=ÉNC ''V'')doif ''V╜''''''''''' °
'U╜r,'' '',W[3],r,''2- +'',W[2],r '': °'',r,''1- °'',r' °
X 'U╜U,'' : °'',r,''0|....|....|.'',V,,'' '',W[1],r,'' 0 1 2'',r' °