home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / teach.zip / TEACH22A.ATF < prev    next >
Text File  |  1997-09-19  |  53KB  |  645 lines

  1. XNÉIO 0 1                                                                      °
  2. XNÉCT 0 1E²13                                                                  °
  3. XCÉFC 1 6 .,*0_²                                                               °
  4. XNÉRL 0 530511967                                                              °
  5. XCÉPR 1 1                                                                      °
  6. XCÉLX 1 5 TEACH                                                                °
  7. *(1996 4 6 16 11 29 328)                                                       °
  8.  FBIND ÉFX 'BIND' 'Σ Binding rules of APL2'                                    °
  9.   '''  1. Brackets bind to the left'''                                         °
  10.   '''  2. Left arrow binds to the left'''                                      °
  11.   '''  3. Dyadic operator binds to the right'''                                °
  12.   '''  4. Strand notation binding'''                                           °
  13.   '''  5. Operator binds to its left'''                                        °
  14.   '''  6. Function binds to its left'''                                        °
  15.   '''  7. Function binds to its right'''                                       °
  16. X '''  8. Left arrow binds to its right'',r'                                   °
  17. *(1996 4 6 16 11 56 436)                                                       °
  18. XFDEGREES ÉFX 'U╜DEGREES W' 'U╜180⌡W÷Ω1'                                       °
  19. *(1997 9 14 12 30 44 504)                                                      °
  20. XFDISCLAIMER ÉFX 'DISCLAIMER' 'Σ Copyright statement' 'disclaimer'             °
  21. *(1996 4 6 16 11 56 436)                                                       °
  22.  FDISPLAY ÉFX 'D╜S DISPLAY A;ÉIO;R;C;HL;HC;HT;HB;VL;VB;V;W;N;B'                °
  23.   'Σ DISPLAY A GENERAL ARRAY IN PICTORIAL FORM'                                °
  24.   'Σ  NORMAL CALL IS MONADIC.  DYADIC CALL USED ONLY IN'                       °
  25.   'Σ    RECURSION TO SPECIFY DISPLAY RANK, SHAPE, AND DEPTH.' 'ÉIO╜0'          °
  26.   '»(0=ÉNC ''S'')/''S╜µA''' 'R╜╞µ,S                   Σ PSEUDO RANK.'          °
  27.   'C╜''┐┌└┘''                 Σ UR, UL, LL, AND LR CORNERS.'                   °
  28.   'HL╜''─''                   Σ HORIZONTAL LINE.'                              °
  29.   'HC╜HL,''Θ╕'',HL,''~+ε''      Σ HORIZONTAL BORDERS.'                         °
  30.   'HT╜HC[(0<R)⌡1+0<╞²1╞,S]' 'ΣW╜,0╧■╞0µΓ(1⌐µA)╞A'                              °
  31.   'HB╜HC[3+3╛(''2⌡~A╧«A'' ÉEA ''1+╞ε0⌡(1⌐⌡/µA)╞,A'')+3⌡1<µµS]'                 °
  32.   'VL╜''│''                   Σ VERTICAL LINE.'                                °
  33.   'VB╜VL,''Φ╟''               Σ VERTICAL BORDER.'                              °
  34.   'V╜VB[(1<R)⌡1+0<²1╞²1╟,S]'                                                   °
  35.   '»(0εµA)/''A╜(1⌐µA)µΓ╞A''   Σ SHOW PROTOTYPE OF EMPTIES.'                    °
  36.   '╕(1<╧A)/GEN' '╕(2<µµA)/D3'                                                  °
  37.   'D╜«A                     Σ SIMPLE ARRAYS.' 'W╜1╞µD╜(²2╞1 1,µD)µD'           °
  38.   'N╜²1+1╟µD' '╕(0=µµA)/SS'                                                    °
  39.   'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[       °
  40.  3]' '╕0' 'SS:HB╜((0 '' '')=╞0µΓA)/'' -'''                                     °
  41.   'D╜'' '',('' '',[0]D,[0]HB,Nµ'' ''),'' ''' '╕0'                              °
  42.   'GEN:D╜«DISPLAY■A          Σ ENCLOSED ...' 'N╜Dδ.⌠'' '''                     °
  43.   'D╜(Nδ~1ΦN)≡D' 'D╜(δ≡~''  ''╤D)/D' 'D╜((1,µS)µS)DISPLAY D'                   °
  44.   '╕(2≥µ,S)╟D3E,0' 'D3:D╜0 ²1╟0 1╟«ΓA         Σ MULT-DIMENSIONAL ...'          °
  45.   'W╜1╞µD' 'N╜²1+1╟µD'                                                         °
  46.   'D╜(C[1],V,((W-1)µVL),C[2]),((HT,NµHL),[0]D,[0]HB,NµHL),C[0],(WµVL),C[       °
  47.  3]' 'D3E:N╜²2+µ,S'                                                            °
  48. X 'V╜C[Nµ1],[0]VB[1+0<²2╟,S],[0](((²3+╞µD),N)µVL),[0]C[Nµ2]' 'D╜V,D'           °
  49. *(1996 4 6 16 11 56 436)                                                       °
  50.  FEXIT ÉFX 'EXIT' 'Σ Exit from function' '''To log off type:   )OFF'''         °
  51. X '╕'                                                                          °
  52. *(1996 4 6 16 11 56 436)                                                       °
  53.  FGO ÉFX 'GO;T;E;B' 'Σ Expression driver' 'L0:B╜E╜''''' 'æ╜''      '''         °
  54.   'T╜æ' '╕(^/'' ''=T)/L0' '╕((^/'')OFF ''=5╞6╟T)doif ''EXIT'')/0'              °
  55.   '╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/L0'                       °
  56.   '''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/L0' '╕B/L0'                                      °
  57.   '''This is not a valid APL2 expression''' 'æ╜''*'''                          °
  58. X '╕(''?''⌠╞1╟æ)/L0' 'E' '╕L0'                                                 °
  59. *(1996 4 6 16 11 56 436)                                                       °
  60.  FGRAD ÉFX 'U╜GRAD A0;AI;SS0;SS1'                                              °
  61.   'Σ Gradient method of function minimization (R and X are global)'            °
  62.   'SS0╜R SS A0 FUN X' 'AI╜3 3µA0' 'U╜SS0-R SS(AI+0.01⌡AI⌡ID 3)FUN X'           °
  63. X 'U╜A0 MIN U÷A0'                                                              °
  64. *(1996 4 6 16 11 56 436)                                                       °
  65.  FGRADIENT ÉFX 'GRADIENT;D' 'Σ Explanation of gradient minimization'           °
  66.   '''The basic idea is to find a direction of search, such that the'''         °
  67.   '''value of SS will decrease the fastest''' '0 2 showfn ''GRAD'''            °
  68.   '''In line [2] of function GRAD, we first compute the sum of squares''       °
  69.  '                                                                             °
  70.   '''associated with A0. Next we want to find the rate of change (slope)       °
  71.  '''                                                                           °
  72.   '''of function SS(A) in each of the components (directions) of A0. To'       °
  73.  '' '''do that we prepare a square array of vectors A0'''                      °
  74.   '0 3 showfn ''GRAD''' 'do'                                                   °
  75.   '''The array AI+0.2⌡AI⌡ID 3 adds to each vector of AI a small incremen       °
  76.  t'''                                                                          °
  77.   '''in each of its components. Finding the difference between SS0 and t       °
  78.  he'''                                                                         °
  79.   '''sum of squares of each of these incremental vectors gives the rate        °
  80.  of''' '''change in each of the component directions'''                        °
  81.   '0 4 showfn ''GRAD'''                                                        °
  82.   '''Finally to get the direction of descent, we divide vector U by A0.'       °
  83.  '' '''This vector is then used as right argument to function MIN'''           °
  84.   '0 5 showfn ''GRAD''' 'do' '''MINIMIZING SS GIVEN A DIRECTION'',r'           °
  85.   '''By its nature a sum of squares of deviations from an mean value'''        °
  86.   '''would be expected to behave in a way similar to the function Y=X*2'       °
  87.  ''                                                                            °
  88.   '''which is a parabola. The estimate of minimum value of function SS(A       °
  89.  )'''                                                                          °
  90.   '''can be made based on that assumption. That is the objective of'''         °
  91.   '''function MIN.''' 'do' '1 showfn ''MIN'''                                  °
  92.   '''The left argument to MIN is the current value of the constant, and'       °
  93.  ''                                                                            °
  94.   '''the right argument is the direction of search. Let us take a closer       °
  95.  ''' '''look at the algorithm of MIN''' 'do' '0 2 showfn ''MIN'''              °
  96.   '''Since SS0 is required here, it is calculated, but only if not known       °
  97.  ''' '''(GRAD may not be the only place where MIN will be applied.)'''         °
  98.   '0 3 showfn ''MIN'''                                                         °
  99.   '''Since we cannot assume that SS(V+W) will be smaller than SS(V),'''        °
  100.   '''the variable T (in units of W) is initialized to ²1 and +1''' 'do'        °
  101.   '0 4 showfn ''MIN'''                                                         °
  102.   '''To insure that only small increments of W (relative to V) are appli       °
  103.  ed,'''                                                                        °
  104.   '''the length of W is normalized to be 1÷100 of the length of V'',r'         °
  105.   '0 5 showfn ''MIN'''                                                         °
  106.   '''Line [5] calculates SS for offsets at ²1 0 and +1''' 'do'                 °
  107.   '''Before we look at the remaining code, let us review some simple'''        °
  108.   '''algebra. We postulate a quadratic function of the form'',r'               °
  109.   '''      Y ╜ a + bX + cXX'',r'                                               °
  110.   '''The minimum (or maximum) can be found by taking derivative and by''       °
  111.  ' '''setting Y'''' to zero'',r' 'do'                                          °
  112.   '''         0= b + 2cX(min)   or  X(min) = -b÷2c'',r'                        °
  113.   '''Since we know this function for X= ²1 0 1, the problem of finding''       °
  114.  ' '''X(min) is reduced to the solution of two equations'',r'                  °
  115.   '''    1╙SS2 ╜ 2╙SS2 -  b +  c'',r'                                          °
  116.   '''    3╙SS2 ╜ 2╙SS2 +  b +  c'',r'                                          °
  117.   '''From these we find that the value of X(min) is given by'',r'              °
  118.   '''    (-/SS2[1 3])÷D╜(+/SS2[1 3])-2⌡SS2[2]''' 'do'                          °
  119.   '''If D>0 then we are dealing with a maximum. In that case we merely''       °
  120.  '                                                                             °
  121.   '''set X(min) to an offset. Lines [6 7] of MIN deal with these cases''       °
  122.  ,r' '0 6 7 showfn ''MIN''' 'do' '0 8 showfn ''MIN'''                          °
  123.   '''Since we cannot be sure that SS(A) will actually behave as a parabo       °
  124.  la'''                                                                         °
  125.   '''we merely add the value of X(min) for which SS(A) should be smalles       °
  126.  t''' '''to T, and compute the associated value of SS'',r'                     °
  127.   '0 9 showfn ''MIN'''                                                         °
  128.   '''Finally we select the constants associated with the smallest value'       °
  129. X'' '''of SS1''' 'do' 'endd'                                                   °
  130. *(1997 8 21 13 29 57 580)                                                      °
  131.  FHELP ÉFX 'HELP;N;I;T' 'Σ Help to student' '''WHAT TO DO'',r'                 °
  132.   '''  ° To get out of the lesson''' '''       ENTER: EXIT'''                  °
  133.   '''  ° To log off APL2'''                                                    °
  134.   '''       FIRST, ENTER: EXIT  THEN ENTER: )OFF'''                            °
  135.   '''  ° To get help''' '''       ENTER: HELP'''                               °
  136.   '''  ° When you see the prompt on a blank line'''                            °
  137.   '''       ENTER AN APL2 EXPRESSION - OR JUST PRESS: ENTER''' 'do'            °
  138.   '''  ° If you get this line'',r'                                             °
  139.   '''This is not a valid APL2 expression'',r,''*'',r'                          °
  140.   '''        YOU CAN EITHER''' '''           A. PRESS: ENTER'''                °
  141.   '''           B. PRESS: ? and then ENTER to see what was incorrect'''        °
  142.   '''              in your expression causing that response'',r' 'do'          °
  143.   '''HINTS'',r'                                                                °
  144.   '''This lesson is made up of '',(«N╜5),'' components named TEACHx, whe       °
  145.  re''' '''the x stands for a digit:'',r' 'I╜0'                                 °
  146.   'L0:T╜''TEACH'',(«I╜I+1)' 'T,'' '',1╟notb(ÉCR T)[2;]' '╕(N>I)/L0'            °
  147.   'do'                                                                         °
  148.   '''You may review either of these components separately. To do that,''       °
  149.  '                                                                             °
  150.   '''first enter EXIT (and RETURN), then enter the name of the lesson.''       °
  151.  ' '''component (e.g. TEACH4).'',r'                                            °
  152.   '''To re-start the lesson, just enter TEACH'',r'                             °
  153.   '''When the screen fills up, it is a good idea to move the cursor to''       °
  154.  ' '''the start of a convenient paragraph, and press ENTER'',r'                °
  155.   '''You may also wish to press PAGE UP to review the prevous pages.'''        °
  156.   'do' '''RESOURCES'',r'                                                       °
  157.   '''You may also enter ONE of the following words at a time'',r'              °
  158.   '''BIND     List the binding rules'''                                        °
  159.   '''GRADIENT To discuss function minimization using a gradient'''             °
  160. X 'endd'                                                                       °
  161. *(1996 4 6 16 11 56 436)                                                       °
  162. XFID ÉFX 'u╜ID w' 'ΣDD' 'u╜(2µw)µ1,wµ0'                                        °
  163. *(1996 4 6 16 11 56 436)                                                       °
  164.  FMIN ÉFX 'U╜V MIN W;SS1;T'                                                    °
  165.   'Σ Find minimum given direction W and constants V (global R, X and SS0       °
  166.  )' 'T╜(0=ÉNC ''SS0'')doif ''SS0╜R SS V FUN X''' 'T╜²1 0 1'                    °
  167.   'W╜0.01⌡W⌡((+/V*2)÷+/W*2)*0.5'                                               °
  168.   'SS1╜²1ΦSS0,R SS((2 3µV)+1 ²1°.⌡W)FUN X'                                     °
  169.   '╕((0≥D╜+/SS1[1 3]-2⌡SS1[2])doif ''T╜T,2⌡╞(SS1=╛/SS1)/²1 0 1'')/L0'          °
  170.   'T╜T,(-/SS1[1 3])÷D' 'L0:SS1╜SS1,R SS(V+T[4])FUN X'                          °
  171. X 'U╜V+W⌡(SS1=╛/SS1)/T'                                                        °
  172. *(1996 4 6 16 11 56 436)                                                       °
  173. XFRADIANS ÉFX 'U╜RADIANS W' 'U╜ΩW÷180'                                         °
  174. *(1997 7 24 13 6 36 412)                                                       °
  175.  FTEACH ÉFX 'TEACH' 'Σ Start lesson #22: APL2 by Zdenek V JIZBA'               °
  176.   'exit ''TEACH''' 'initialize' 'TEACH1 Σ Matrix divide'                       °
  177.   'TEACH2 Σ The grocery problem revisited'                                     °
  178.   'TEACH3 Σ Fitting observed data to a polynomial'                             °
  179.   'TEACH4 Σ Fitting obseved data to other equations'                           °
  180. X 'TEACH5 Σ Function minimization' 'problems'                                  °
  181. *(1997 7 23 13 48 46 616)                                                      °
  182.  FTEACH1 ÉFX 'TEACH1;ROWS;COLS;BILL;BUY;PRICE;COST;INB;GRNO'                   °
  183.   'Σ Solving linear equations with dyadic domino'                              °
  184.   '''    MATRIX DIVIDE'',r' 'BUY╜3 3µ2 1 1 1 2 2 3 2 1'                        °
  185.   'PRICE╜0.3 0.4 0.5' 'COST╜BUY+.⌡PRICE'                                       °
  186.   '''In the previous lesson we learned about matrices, geometrical vecto       °
  187.  rs'''                                                                         °
  188.   '''(as contrasted with APL2 vectors, -- a more general concept), and w       °
  189.  e'''                                                                          °
  190.   '''studied the APL2 primitive function called MATRIX INVERSE.'',r'           °
  191.   '''As an example of the use of matrix inverse we solved the grocery'''       °
  192.   '''price of fruit problem: Given the purchase of fruit by three'''           °
  193.   '''customers, find the unit cost of each fruit. We defined a matrix'''       °
  194.   '''BUY and two vectors COST and PRICE'',r'                                   °
  195.   'show ''COST      BUY     PRICE'''                                           °
  196.   '''In this problem, PRICE is the unknown'',r'                                °
  197.   'ROWS╜πΓ■''CUSTOMER 1'' ''CUSTOMER 2'' ''CUSTOMER 3'''                       °
  198.   'COLS╜'''' ''APPLES'' ''ORANGES'' ''BANANAS'' '' COST'''                     °
  199.   'BILL╜3 1µΓ[2]3 6µ(ÉAV[33 37],''0.59'')«COST' 'COLS,[1]ROWS,BUY,BILL'        °
  200.   'do'                                                                         °
  201.   '''To solve this problem, we first found the inverse of matrix BUY, th       °
  202.  en''' '''we multiplied this inverse by COST'',r'                              °
  203.   'show ''INB╜ÆBUY'' ''INB+.⌡COST'''                                           °
  204.   '''In the dyadic version of the DOMINO primitive, this procedure can b       °
  205.  e''' '''accomplished in a single step'',r' 'show ''COSTÆBUY'''                °
  206.   '''This dyadic function is called MATRIX DIVIDE, since it is a'''            °
  207.   '''generalization of division into the matrix domain. The right argume       °
  208.  nt'''                                                                         °
  209.   '''to matrix divide should be a matrix. The left argument can be a vec       °
  210.  tor'''                                                                        °
  211.   '''or a matrix. Suppose that in the grocery problem, we compare the co       °
  212.  sts''' '''of the same items from two or more groceries'',r'                   °
  213.   'show ''É╜GRNO╜3 3µ1.5 2.1 2.2 1.3 1.85 1.9 1.5 2.1 2.25'' ''(φGRNO)ÆB       °
  214.  UY'''                                                                         °
  215.   '''The columns of the result return the unit costs of each item.'',r'        °
  216.   'BILL╜(φ3 3µ1.5 2.1 2.2 1.3 1.85 1.9 1.5 2.1 2.25)ÆBUY'                      °
  217.   '('''' ''STORE 1'' ''STORE 2'' ''STORE 3''),[1](3 1µ1╟COLS),BILL'            °
  218.   'do'                                                                         °
  219.   '''Although matrix BUY is a square one, this is not a requirement, as'       °
  220.  ''                                                                            °
  221.   '''we will see shortly. For matrix divide to work, however there are''       °
  222.  ' '''some limitations:'',r' '''    A. Right argument'',r'                     °
  223.   '''       1. If it is a vector, there is no matrix divide. The result        °
  224.  is'''                                                                         °
  225.   '''          related to the monadic version and the following identity       °
  226.  ''' '''          holds:'',r'                                                  °
  227.   '''             V1+.⌡ÆV2   ╜  ╕  V1ÆV2     or'''                             °
  228.   '''             (φM)+.⌡ÆV  ╜  ╕  MÆV2'',r'                                   °
  229.   '''       2. If the right argument is a matrix, the number of columns'       °
  230.  ''                                                                            °
  231.   '''          must not exceed the number of rows. Also no column may be       °
  232.  '''                                                                           °
  233.   '''          the same as the matrix product of the remaining columns.'       °
  234.  '' '''          This requirement is called LINEAR INDEPENDENCE.'''            °
  235.   'do' '''    B. Left argument'',r'                                            °
  236.   '''       1. If it is a vector, its length must match the number of'''       °
  237.   '''          rows in the right argument.'',r'                                °
  238.   '''       2. If the left argument is an array, the number of rows'''         °
  239.   '''          must be the same as the number of rows of the right'''          °
  240.   '''          argument.'',r'                                                  °
  241.   '''    C. If both arguments are simple scalars, Æ is the same as ÷'''        °
  242.   'do'                                                                         °
  243.   '''Next let us describe the meaning of XÆY when Y is not a square'''         °
  244. X '''matrix.''' 'endd'                                                         °
  245. *(1997 7 23 13 54 59 692)                                                      °
  246.  FTEACH2 ÉFX 'TEACH2;D;BUY;PRICE;COST' 'Σ Least squares' 'D╜ÉAV[37]'           °
  247.   '''     FITTING BY LEAST SQUARES'',r'                                        °
  248.   'BUY╜4 3µ2 1 1 1 2 2 3 2 1 2 2 2' 'PRICE╜0.3 0.4 0.5'                        °
  249.   'COST╜BUY+.⌡PRICE'                                                           °
  250.   '''Suppose that we add a fourth customer to our list. This one bought'       °
  251.  '' '''two apples, two oranges, and two bananas, paying $2.40'',r'             °
  252.   'show ''BUY'' ''COST'''                                                      °
  253.   '''We can still use the same expression to determine the PRICE of each       °
  254.  ''' '''unit'',r' 'show ''COSTÆBUY'''                                          °
  255.   '''Adding an extra customer really did not do anything. The new data''       °
  256.  '                                                                             °
  257.   '''is redundant. But suppose that the price of the fruit is not on a''       °
  258.  ' '''unit basis, but rather on a per/pound basis. If the fourth'''            °
  259.   '''customer selected somewhat smaller than average fruit, the cost'''        °
  260.   '''may have been $2.35 instead of $2.40. Will the same expression'''         °
  261.   '''work, and if yes, what does it mean?'',r'                                 °
  262.   'show ''COST[4]╜2.35'' ''8 2«.005+COSTÆBUY'''                                °
  263.   '''(Why did we insert the expression ''''8 2«.005+''''?)''' 'do'             °
  264.   '''The numbers we now get represent the AVERAGE cost of each'''              °
  265.   '''fruit. To explain precisely the underlying mathematics of the'''          °
  266.   '''calculation would take us too far into a subject called'''                °
  267.   '''MATHEMATICAL STATISTICS. We can however explain the basic idea.'''        °
  268.   'do'                                                                         °
  269.   '''Let us assume that the grocery store would like to receive on the''       °
  270.  '                                                                             °
  271.   '''average the amounts of 0.30 0.40 and 0.50 each for one apple, one''       °
  272.  '                                                                             °
  273.   '''orange and one banana. To do that, they find the average weight of'       °
  274.  ''                                                                            °
  275.   '''these fruit, and price the per/pound accordingly. When we select'''       °
  276.   '''specific fruit, we find that the deviation from the average can be'       °
  277.  '' '''positive or negative'',r' 'show ''PRICE-COSTÆBUY'''                     °
  278.   '''We would like to treat the negative numbers the same as the positiv       °
  279.  e'''                                                                          °
  280.   '''numbers. There are several ways to do that, but as Karl Gauss showe       °
  281.  d'''                                                                          °
  282.   '''in 1795, the best way is to square these differences and add them u       °
  283.  p'',r' 'show ''+/(PRICE-COSTÆBUY)*2'''                                        °
  284.   '''This quantity, called the SUM OF SUARES (often abbreviated SS)'''         °
  285.   '''should be minimized for a best estimate. This is indeed what'''           °
  286.   '''the expression COSTÆBUY actually does!''' 'do'                            °
  287.   '''The method of LEAST SQUARES is a very general one. It is the'''           °
  288.   '''foundation of a great deal of applied statistics. We will not'''          °
  289.   '''deal with this extensive subject here, except to point out that'''        °
  290.   '''APL2 is an ideal language for solving problems of a statistical'''        °
  291.   '''nature. We will give more examples including some techniques for'''       °
  292. X '''the solution of very difficult problems.''' 'endd'                        °
  293. *(1997 7 24 12 47 9 464)                                                       °
  294.  FTEACH3 ÉFX 'TEACH3;A;X;Y;A1;YOBS1;YOBS2;SS1N;SS1R;YTH'                       °
  295.   'Σ Fitting curves' '''FITTING CURVES'',r'                                    °
  296.   '''Let us suppose that a scientist has reason to believe that every'''       °
  297.   '''time a value is set for variable X, the value for variable Y'''           °
  298.   '''should be determined by a polynomial of the form'',r'                     °
  299.   '''       Y = A + (B⌡X) + (C⌡XX)'',r'                                        °
  300.   '''(As before we write XX to represent X*2)'',r'                             °
  301.   '''Furthermore, let us suppose that unknown to the scientist, the'''         °
  302.   '''value of constants A, B and C is 4 2 ²0.3''' 'do'                         °
  303.   '''The polynomial equation can be written as an APL2 expression'',r'         °
  304.   '''     A[1]+X⌡A[2]+X⌡A[3]     where'',r'                                    °
  305.   '''Why is the expression "a+X⌡b+X⌡c" equivalent to "a+(bX)+(cXX)"?'',r       °
  306.  ' 'show ''A╜4 2 ².3'''                                                        °
  307.   '''The belief that there is a specific relation between X and Y is cal       °
  308.  led'''                                                                        °
  309.   '''a HYPOTHESIS. To demonstrate the validity of the hypothesis, the'''       °
  310.   '''scientist must do the following:'',r'                                     °
  311.   '''      1. Take a number of measurements of X and Y'''                      °
  312.   '''      2. Find the "best" constants A, B and C'''                          °
  313.   '''      3. Show that the polynomial is "a good fit".''' 'do'                °
  314.   '''Since the values of X can be selected before an experiment, let us'       °
  315.  ''                                                                            °
  316.   '''assume that this choice is without error. (If we cannot select X'''       °
  317.   '''without error, the theory gets much more complex.)'',r'                   °
  318.   'show ''X╜∞10'''                                                             °
  319.   '''We can now calculate the values of Y that would be predicted by'''        °
  320.   '''theory given vector A'',r' 'show ''Y╜A[1]+X⌡A[2]+X⌡A[3]'' ''Y'''          °
  321.   'do'                                                                         °
  322.   '''We can verify that these values are correct, by recovering A from''       °
  323.  ' '''X, Y and the equation'',r' 'show ''YÆ1,X°.*1 2'''                        °
  324.   '''In a typical experiment, the scientist obtains Y by making measurem       °
  325.  ents.'''                                                                      °
  326.   '''We can simulate this process by adding a random error to the values       °
  327.  '''                                                                           °
  328.   '''of vector Y. We will call the vector of observed Y''''s YOBS1'',r'        °
  329.   'show ''YOBS1╜Y+.01⌡²10+?10µ19'' ''YOBS1'''                                  °
  330.   '''The results can be used to estimate vector A. We will call this vec       °
  331.  tor''' '''A1 because it is only an ESTIMATE of A'',r'                         °
  332.   'show ''É╜A1╜YOBS1Æ1,X°.*1 2'''                                              °
  333.   '''If the errors of measurement are greater, our estimate of A will'''       °
  334.   '''deviate more from the theoretical values'',r'                             °
  335.   'show ''YOBS2╜Y+.05⌡²10+?10µ19'' ''YOBS2'''                                  °
  336.   'show ''YOBS2Æ1,X°.*1 2'''                                                   °
  337.   '''At this point we have taken two of the three steps: We have made'''       °
  338.   '''the observations, and we have estimated the PARAMETERS (namely the'       °
  339.  ''                                                                            °
  340.   '''vector A). We still need to determine to what extent the hypothesis       °
  341.  ''' '''is correct. Here is a brief outline of that process:''' 'do'           °
  342.   '''The basic idea is to show that the hypothesis explains the outcome'       °
  343.  ''                                                                            °
  344.   '''of the experiment better than no hypothesis, (also called the NULL'       °
  345.  ''                                                                            °
  346.   '''HYPOTHESIS). If we have no theory, then the SUM OF SQUARES of the''       °
  347.  '                                                                             °
  348.   '''observations is defined as the SUM OF DEVIATIONS FROM THE AVERAGE.'       °
  349.  '' '''We will call this quantity SS1N'',r'                                    °
  350.   'show ''SS1N╜+/(YOBS1-(+/YOBS1)÷µYOBS1)*2'''                                 °
  351.   '''On the other hand given the estimated values of vector A, we can'''       °
  352.   '''also obtain the theoretical values of Y'',r'                              °
  353.   'show ''YTH╜(1,X°.*1 2)+.⌡A1'''                                              °
  354.   '''and from these obtain the RESIDUAL SUM OF SQUARES'',r'                    °
  355.   'show ''SS1R╜+/(YOBS1-YTH)*2'''                                              °
  356.   '''Comparing the values of SS1N and SS1R (and applying a number of'''        °
  357.   '''special equations), it is possible to determine the LIKELIHOOD'''         °
  358.   '''that the hypothesis is correct. For YOBS1 there is not much doubt''       °
  359.  ' '''that the polynomial makes a good prediction'',r'                         °
  360.   'show ''SS1N'' ''SS1R'''                                                     °
  361.   '''(You might also try these calculations for the estimate YOBS2)'''         °
  362. X 'endd'                                                                       °
  363. *(1997 7 24 12 53 46 636)                                                      °
  364.  FTEACH4 ÉFX 'TEACH4;A;G;R;R1' 'Σ Fitting trigonomrtric functions'             °
  365.   '''   FITTING TRIGONOMETRIC FUNCTIONS'',r'                                   °
  366.   '''Suppose now that instead of a polynomial, the equation that the'''        °
  367.   '''scientist desires to fit involves trigonometric functions'',r'            °
  368.   '''     R = a + b(cosα) + c(cos2α)'',r'                                      °
  369.   '''Here again we will set vector A to contain the values a,b and c, an       °
  370.  d''' '''set'',r' 'show ''A╜1 2 3'''                                           °
  371.   '''Then this equation can represented by the following expression'',r'       °
  372.   '''      R╜A[1]+(2ΩG°.⌡1 2)+.⌡A[2 3]'',r'                                    °
  373.   '''where G is the vector of angles expressed in radians.''' 'do'             °
  374.   '''In the theory of least squares, this is treated exactly the same'''       °
  375.   '''as the problem of fruit in the grocery store. We merely treat the''       °
  376.  '                                                                             °
  377.   '''cosines as unknown variables. You may think of them as if we made''       °
  378.  ' '''the following transformations'',r'                                       °
  379.   '''       X╜cosα    and  Y╜cos2α.'',r' '''Given angles G'',r'                °
  380.   'show ''G╜RADIANS 0,10⌡∞9''' '''We find the values for R'',r'                °
  381.   'show ''É╜R╜A[1]+(2ΩG°.⌡1 2)+.⌡A[2 3]'''                                     °
  382.   '''and given observations R1'',r' 'show ''R1╜R+.001⌡(?10µ19)-10'''           °
  383.   '''we get an estimate of A, say A1'',r' 'show ''R1Æ1,2ΩG°.⌡1 2'''            °
  384.   '''A more difficult problem arises if the theory leads us to the'''          °
  385.   '''following equation'',r' '''      R ╜ a + cos(b+α) - cos(c+2α)'',r'        °
  386.   '''The theory of least squares can still be applied, but now the'''          °
  387.   '''equations no longer fall in the domain of linear algebra. The'''          °
  388.   '''problem is still soluble but requires a different strategy.'''            °
  389.   '''Often, tailor made algorithms have to be optimised for each'''            °
  390. X '''individual problem.''' 'endd'                                             °
  391. *(1997 7 24 13 2 10 292)                                                       °
  392.  FTEACH5 ÉFX 'TEACH5;A;A0;A1;D;R;X;FN;FUN;SS;LOOP'                             °
  393.   'Σ Function minimization' '''   FUNCTION MINIMIZATION'',r'                   °
  394.   '''There are general techniques for the solution of this type of'''          °
  395.   '''problem, but these may not be efficient, and in many cases not'''         °
  396.   '''even reach the true least squares solution. Just to illustrate'''         °
  397.   '''how these techniques work, we will attempt to find the constants'''       °
  398.   '''a, b and c in the following equation.'',r'                                °
  399.   '''      R ╜ cos(a+x) + cos(b+2x) + cos(c+3x)'',r'                           °
  400.   '''We will use the method of gradients, also known as the method of'''       °
  401.   '''STEEPEST DESCENT. We begin by defining vector A to contain the'''         °
  402.   '''values of a, b and c'',r' 'show ''A╜1 2 3'''                              °
  403.   '''This time when translating the equation into an APL2 expression,'''       °
  404.   '''we define a function that calculates R, given A and X. We also must       °
  405.  '''                                                                           °
  406.   '''define the function in such a way that it will calculate R for more       °
  407.  ''' '''than one set of A''''s.'',r'                                           °
  408.   'show ''FN╜''''R╜A FUN X'''' ''''Σ cos(1╙A+X)+cos(2╙A+2⌡X)+cos(3╙A+3⌡X       °
  409.  )'''''''                                                                      °
  410.   'show ''FN╜FN,Γ''''╕((2=µµA)doif ''''''''R╜φπ(Γ[2]A) FUN■ ΓX'''''''')/       °
  411.  0''''''' 'show ''ÉFX FN,Γ''''R╜+/2ΩA+[2]X°.⌡∞3'''''''                         °
  412.   '1 showfn ''FUN''' 'do'                                                      °
  413.   '''Next, for convenience, we also define a function to calculate the''       °
  414.  '                                                                             °
  415.   '''sum of squares with α╜R and ∙╜A FUN X where A may be an array'',r'        °
  416.   '1 show ''SS:+≡((φ(Φµ∙)µα)-∙)*2'''                                           °
  417.   '''To set up the problem, we define X, and observations R'',r'               °
  418.   'show ''X╜RADIANS 0,10⌡∞9''' 'show ''R╜(A FUN X)+.001⌡(?10µ19)-10'''         °
  419.   '''The basic idea for the general solution is to start with an initial       °
  420.  '''                                                                           °
  421.   '''estimate of A, find the associated SS, and then try to migrate A'''       °
  422.   '''such that SS is constantly reduced. The expectation is that with'''       °
  423.   '''enough iterations, the values of A will approach the least squares'       °
  424.  '' '''solution.''' 'do'                                                       °
  425.   '''Let us begin with an initial value of A0'',r'                             °
  426.   'show ''A0╜1.5 1.5 2.5'' ''A-A0'''                                           °
  427.   '''Function GRAD takes as the right argument this estimate, and return       °
  428.  s''' '''the new value of A with reduced value of SS'',r'                      °
  429.   '1 showfn ''GRAD'''                                                          °
  430.   '''For more details on the gradient approach, type GRADIENT'',r'             °
  431.   'show ''R SS A0 FUN X'' ''A1╜GRAD A0'' ''R SS A1 FUN X'''                    °
  432.   '''One iteration seldom reaches the minimum. We can define function'''       °
  433.   '''LOOP to iterate more than once, and see the rate of convergence'''        °
  434.   '''with the gradient technique'',r'                                          °
  435.   'show ''FN╜''''LOOP W;S;SS0'''' ''''Σ minimization with gradient'''' '       °
  436.  '''S╜0'''''''                                                                 °
  437.   'show ''FN╜FN,''''L0:A1╜GRAD A1'''' ''''²1╞S╜S,SS0╜R SS A1 FUN X''''''       °
  438.  ' 'show ''ÉFX FN╜FN,''''╕(=/²2╞S)/0'''' ''''╕(0<W╜W-1)/L0'''''''              °
  439.   '1 showfn ''LOOP''' 'do'                                                     °
  440.   '''Note that exit from LOOP ocurrs if the new value of S is unchanged'       °
  441.  ',r' 'show ''LOOP 10'''                                                       °
  442.   '''The result will not necessarily converge to the least squares'''          °
  443.   '''solution, because it may get caught in what is known as a LOCAL'''        °
  444.   '''MINIMUM. There are ways of avoiding such local minima. We can'''          °
  445.   '''check whether the estimate A0 is approaching the true value of A'',       °
  446.  r' 'show ''A'' ''A0'' ''A-A0'' ''A-A1'''                                      °
  447.   '''In this example, we may not be in a local minimum, but in a valley.       °
  448.  '''                                                                           °
  449.   '''Think of a river gorge. The steepest slopes point down to the'''          °
  450.   '''river, but the direction of global minimum is at right angles to'''       °
  451.   '''this slope. We can ammend LOOP by adding an extra search in the'''        °
  452.   '''direction A1-A0'',r'                                                      °
  453.   'show ''ÉFX (²1╟FN),''''A1╜A MIN A1-A0'''' ''''²1╞S,R SS A1 FUN X'''',       °
  454.  ²1╞FN''' '1 showfn ''LOOP''' 'do' '''And try again'',r'                       °
  455.   'show ''A1╜A0'' ''LOOP 10''' '''This time the search converges.'''           °
  456. X 'show ''A1'' ''A-A1''' 'endd'                                                °
  457. *(1997 7 13 12 28 49 504)                                                      °
  458.  Faddquote ÉFX 'u╜addquote w'                                                  °
  459.   'Σ Put quotes around a string, and double existing quotes'                   °
  460. X 'u╜ÉAV[40],((1+w=ÉAV[40])/w),ÉAV[40]'                                        °
  461. *(1996 4 6 16 11 56 436)                                                       °
  462. XFaq ÉFX 'U╜aq W' 'U╜Γaddquote W'                                              °
  463. *(1997 7 24 13 20 38 476)                                                      °
  464.  Fav ÉFX 'av;A;N;I;ÉIO' 'Σ Display characters in ÉAV' 'ÉIO╜0'                  °
  465.   'A╜22 78µ'' ''' 'N╜3 0«φ12 22µ1+∞356' 'A[;,(6⌡∞12)°.+2 3 4]╜N'               °
  466.   'A[;6+6⌡∞12]╜φ12 22µÉAV' 'ΣA[8 10 13;6]╜'' ''' 'A[13;6]╜'' '''               °
  467. X 'A[14+∞8;68 69 70 72]╜'' ''' 'A'                                             °
  468. *(1991 11 11 8 25 13 316)                                                      °
  469.  Fdate ÉFX 'u╜date w' 'Σ Format date and time of day' 'u╜«6╞w'                 °
  470. X 'u╜('' ''⌠u)Γu' 'u╜εu,■''-- .. '''                                           °
  471. XCdig 1 10 1234567890                                                          °
  472. *(1997 9 9 13 0 45 372)                                                        °
  473.  Fdisclaimer ÉFX 'disclaimer' 'Σ Copyright statement'                          °
  474.   '(10µ'' ''),''Copyright, Z. V. Jizba, 1995,1996,1997'',r'                    °
  475.   ''' This and subsequent workspaces labelled TEACHxx are made available       °
  476.  '''                                                                           °
  477.   '''at no cost to anyone who desires to learn how to use effectively'''       °
  478.   '''the IBM/OS2 version of APL2.'',r'                                         °
  479.   '''This software is provided "AS IS" with no WARRANTY of any kind, eit       °
  480.  her'''                                                                        °
  481.   '''express or implied. Any risk in its use resides with you, the user        °
  482.  of''' '''these tutorials.'',r' '''     ACKNOWLEDGEMENTS'',r'                  °
  483.   ''' In writing these tutorials, I am greatly indebted to Roy Sykes, wh       °
  484.  ose'''                                                                        °
  485.   '''excellent lectures increased my understanding of the language.'''         °
  486.   '''Discussions with the late Harry Bertucelli clarified a number of'''       °
  487.   '''concepts and caused me to change some improper terminology that was       °
  488.  '''                                                                           °
  489.   '''used in previous versions of these tutorials. Mr. Benjamin Archer''       °
  490.  '                                                                             °
  491.   '''kindly checked out a nearly final version, bringing to my attention       °
  492.  ''' '''some ommisions, misspellings, and invalid terminology.'',r'            °
  493. X '''(PRESS ENTER to continue)'''                                              °
  494. *(1997 7 13 12 28 50 508)                                                      °
  495.  Fdo ÉFX 'do;T;E' 'Σ Expression driver' 'E╜''''' 'æ╜''      ''' 'T╜æ'          °
  496.   '╕(^/'' ''=T)/0'                                                             °
  497.   '╕(('':''εT)doif ''B╜evaldd (+/^\'''' ''''=T)╟T'')/2'                        °
  498.   '''E╜ÉEM'' ÉEA T' '╕(0=µ,E)/2'                                               °
  499.   '''This is not a valid APL2 expression''' 'æ╜''*''' '╕(''?''⌠╞1╟æ)/2'        °
  500. X 'E' '╕2'                                                                     °
  501. *(1997 7 13 12 28 50 508)                                                      °
  502.  Fdoif ÉFX 'U╢╜V╢ doif W╢;t╢' 'Σ Rule' '╕(^/~U╢╜V╢)/0'                         °
  503. X '''U╢╜V╢ doif■ W╢'' ÉEA ''»V╢/W╢'''                                          °
  504. *(1997 9 9 12 50 14 444)                                                       °
  505.  Fendd ÉFX 'endd' 'Σ end of special feature' '20µ''²'' ╪ ╕(4<µÉLC)/0'          °
  506. X 'do'                                                                         °
  507. *(1997 8 21 13 30 22 444)                                                      °
  508.  Ferase ÉFX                                                                    °
  509.   'erase;t;EXIT;GO;BIND;HELP;DISPLAY;ID;DEGREES;RADIANS;MIN;GRADIENT;GRA       °
  510.  D;DISCLAIMER' 'Σ Erase all global functions and variables' 't╜ÉNL 3'          °
  511.   't╜(~t^.εlc,'' '')≡t' 't╜ÉEX(~t[;∞5]^.=''TEACH'')≡t' 't╜ÉNL 2'               °
  512. X 't╜ÉEX(~t^.εlc,'' '')≡t' 't╜ÉNL 4' 't╜ÉEX(~t^.εlc,'' '')≡t'                  °
  513. *(1997 7 27 13 47 41 608)                                                      °
  514.  Fevaldd ÉFX 'u╜evaldd w;c;n' 'Σ Evaluate direct definition' 'u╜0'             °
  515.   'n╜(w∞''Σ'')-1' 'c╜(((n╞w)⌠'':'')Γn╞w),Γ''ΣDD '',(n+1)╟w'                    °
  516.   '╕((1 label╞c)doif ''''''Invalid label'''''')/0'                             °
  517.   '╕((2=µc)doif ''u╜showdd 1╙c'')/0'                                           °
  518.   '╕((3=ÉNC╞c)doif ''u╜⌡µÉ╜(╞c),'''' is already defined.'''''')/0'             °
  519.   '╕((3=µc)doif ''u╜simdd c'')/0' 'c╜(Γ''α∙ aw'')replace■c'                    °
  520.   'u╜ε''u╜'',((''a''εεc[2 3 4])/''a ''),(╞c),'' w;t;b'''                       °
  521.   'u╜u(5πc)(''b╜(t╜'',(3πc),'')/'',addquote ''u╜'',4πc)'                       °
  522. X 'u╜u,''╕(t doif b)/0''(''u╜'',2πc)' 'u╜╧ÉFX u'                               °
  523. *(1997 7 25 13 27 52 564)                                                      °
  524.  Fexit ÉFX 'V exit W;T' 'Σ Exit if too many suspended functions'               °
  525.   '╕(0⌠ÉNC ''V'')/L0 ╪ V╜10' 'L0:╕(V>µÉLC)/0'                                  °
  526.   '''There are too many suspended functions''' '''Please enter '',W'           °
  527. X '╕'                                                                          °
  528. *(1997 7 26 12 33 39 536)                                                      °
  529.  Fget ÉFX 'U╜V get W;t;T;ÉPR' 'Σ Prompt for response from keyboard'            °
  530.   'ÉPR╜T╜ÉAV[ÉIO+255] ╪ ╕(0⌠ÉNC ''V'')/L0 ╪ V╜1' 'L0:V╜V╧1' 'æ╜W ╪ t╜æ'        °
  531.   'U╜(+/^\t=T)╟t' '╕(''╕''⌠╞U)/L1 ╪ ╕' 'L1:╕V/0' 't╜(U⌠'' '')ΓU'               °
  532. X 'U╜(µt),(ΓU),t'                                                              °
  533. *(1997 7 28 13 33 8 424)                                                       °
  534.  Fglobals ÉFX 'globals' 'Σ Initialize useful global variables'                 °
  535.   'uc╜''ABCDEFGHIJKLMNOPQRSTUVWXYZ'''                                          °
  536.   'lc╜''abcdefghijklmnopqrstuvwxyz''' 'dig╜''1234567890'''                     °
  537. X 'r╜ÉAV[13+ÉIO]' 'q╜'''''''''                                                 °
  538. *(1997 7 3 12 47 6 368)                                                        °
  539.  Finitialize ÉFX 'initialize;T' 'Σ Initialize workspace'                       °
  540.   '''AT ALL TIMES, TO CONTINUE, PRESS RETURN!'',r'                             °
  541.   '''To see disclaimers enter:'',r,''    disclaimer''' 'do' 'erase'            °
  542.   'globals'                                                                    °
  543.   '''Make sure the CAP LOCK light on your keyboard (upper right) is ON!'       °
  544. X'' 'endd'                                                                     °
  545. *(1997 7 27 13 14 33 444)                                                      °
  546.  Flabel ÉFX 'u╜v label w'                                                      °
  547.   'Σ Return 1 if label w does not begin with a cap'                            °
  548.   '╕(0⌠ÉNC ''v'')/L0 ╪ v╜0' 'L0:v╜v╧1 ╪ w╜εw ╪ ╕v/L1 ╪ ╕(u╜0⌠ÉNC w)/0'         °
  549. X 'L1:╕(u╜~^/wεlc,uc,dig)/0' 'u╜w[1]εlc,dig'                                   °
  550. XClc 1 26 abcdefghijklmnopqrstuvwxyz                                           °
  551. *(1997 7 13 12 28 55 528)                                                      °
  552.  Fnon ÉFX 'non;T;RC;ET;R' 'Σ Ignore keyboard entry' 'æ╜''      ''' 'T╜æ'       °
  553.   '╕(0=µ(T⌠'' '')/T)/0' '(RC ET R)╜ÉEC T' '╕(0=RC)/2'                          °
  554. X '╕((1=RC)doif ''R'')/2' '╕2'                                                 °
  555. *(1997 7 13 12 28 55 528)                                                      °
  556.  Fnotb ÉFX 'u╜notb w' 'Σ Remove trailing blanks'                               °
  557.   '╕((1<╧w)doif ''u╜notb■ w'')/0' '╕((1<µµw)doif ''u╜πnotb Γ[2]w'')/0'         °
  558. X 'u╜(1-(,'' ''⌠Φw)∞1)╟w'                                                      °
  559. *(1996 4 6 16 11 57 440)                                                       °
  560.  Fpause ÉFX 'V pause W;T'                                                      °
  561.   'Σ Pause, then print W V spaces right and return'                            °
  562. X 'T╜(0=ÉNC ''V'')doif ''V╜6''' 'do' '(Vµ'' ''),W' 'do'                        °
  563. *(1997 7 27 12 55 6 496)                                                       °
  564.  Fproblems ÉFX 'problems' 'Σ Problems'                                         °
  565.   '''That is all for this lesson. Remember, if you want to practice,'''        °
  566.   '''and plan to use direct definitions, be sure to first enter GO.'''         °
  567.   '''Direct definitions will then be accepted. To exit GO, enter EXIT.''       °
  568.  ,r'                                                                           °
  569.   '''To erase a previously defined DIRECT DEFINITION FUNCTION, enter'',r       °
  570.  ' '''       )ERASE functionname'',r'                                          °
  571. X '''WARNING! do not use )ERASE on other labels.'',r'                          °
  572. XCq 0 '                                                                        °
  573. XCr 0                                                                         °
  574. *(1997 7 13 12 28 56 532)                                                      °
  575.  Freplace ÉFX 'u╜v replace u;i;r;s' 'Σ Replace elements in v in u'             °
  576.   'i╜Γ∞µu' 's╜2πv╜(v⌠'' '')Γv' 'i╜⌡r╜i⌡■Γ[1]u°.=╞v'                            °
  577. X 'u[(εi)/εr]╜s[(εi)/εi⌡■∞µs]'                                                 °
  578. *(1997 7 13 12 28 56 532)                                                      °
  579.  Fround ÉFX 'U╜V round W' 'Σ Half adjust to V th decimal'                      °
  580. X 'U╜(╛0.5+W⌡10*V)÷10*V'                                                       °
  581. *(1997 7 13 12 28 57 536)                                                      °
  582.  Fshow ÉFX '╢V show ╢W;╢T;╢B' 'Σ Display and execute ╢W'                       °
  583.   '╢T╜(0=ÉNC ''╢V'')doif ''╢V╜0'''                                             °
  584.   '╕((0=╧╢W)doif ''show ╢W,'''' '''''')/0'                                     °
  585.   '╕((1<╧╢W)doif ''╢V show ■╢W'')/0' '''      '',╢W'                           °
  586. X '╕((╢V^'':''ε╢W)doif ''╢T╜evaldd ╢W'')/L0' '''ÉEM'' ÉEA ╢W' 'L0:do'          °
  587. *(1997 7 13 12 28 57 536)                                                      °
  588.  Fshowdd ÉFX 'u╜showdd w;a;b;c;r'                                              °
  589.   'Σ Display a direct definition function'                                     °
  590.   '╕((1=╧w)doif ''u╜showdd Γw'')/u╜0'                                          °
  591.   '╕((3⌠ÉNC╞w)doif ''(ε╞w),'''' is not a function'''''')/0'                    °
  592.   'c╜Γ[2]ÉCR╞w' 'c╜notb(2╞c),(Γ''aw α∙'')replace■2╟c'                          °
  593.   '╕((~''ΣDD''╧3╞2πc)doif ''''''Not a direct definition function'''''')/       °
  594.  0' 'u╜1' 'b╜('' ''⌠╞c)Γ╞c' 'a╜''      ''' 'r╜2╟3πc'                           °
  595.   '╕((3=µc)doif ''a,(╞w),'''':'''',r,(3<µ2πc)/''''   Σ'''',3╟2πc'')/0'         °
  596.   'a╜a,(╞w),'':'',(2╟5πc),'':''' 'b╜(+\r=''('')-+\r='')''' 'b╜b∞0'             °
  597. X 'a╜a,(²3╟(b-1)╞3╟r),'':'',2╟»(b+2)╟r' 'a,(3<µ2πc)/''  Σ'',3╟2πc'             °
  598. *(1997 7 13 12 28 57 536)                                                      °
  599.  Fshowfn ÉFX 'U╜V showfn W;F;N;T;ÉIO' 'Σ Simulate ╖W[É]'                       °
  600.   'T╜(0=ÉNC ''V'')doif ''V╜0''' 'ÉIO╜0'                                        °
  601.   'U╜r,''      '',''╖'',W,''[É]'',(╞V)╞''╖''' 'N╜1╞µF╜ÉCR W' 'N╜«∞N'           °
  602.   'N╜(N⌠'' '')ΓN' 'F╜(π''['',■N,■Γ''] ''),F'                                   °
  603.   'T╜(1<µ,V)doif ''F╜F[1╟V;]'' ''U╜''''''''''' 'U╜²1╟U,r,,F,r'                 °
  604. X 'U╜((-+/^\'' ''=ΦU)╟U),('' ╖'')[╞V],r'                                       °
  605. *(1997 7 13 12 28 58 540)                                                      °
  606.  Fsimdd ÉFX 'u╜simdd w;e' 'Σ Direct definition mode' 'u╜0'                     °
  607.   '╕((0⌠ÉNC╞w)doif ''''''Already defined'''''')/0' 'e╜''α''ε2πw'               °
  608.   'w[2]╜Γ''u╜'',''α∙ aw'' replace 2πw' 'w╜w[1 3 2]'                            °
  609. X 'w[1]╜Γε''u╜'',(e/''a ''),w[1],'' w''' 'u╜╧ÉFX w'                            °
  610. *(1992 6 3 9 59 17 424)                                                        °
  611.  Ftab ÉFX 'U╜V tab W;T;A;B;C;D;E;F;G;M;ÉPW' 'Σ Tabulate list W'                °
  612.   'T╜(0=ÉNC ''V'')doif ''V╜0''' 'M╜''Invalid data for tabulation'''            °
  613.   'V╜4╞V' 'ÉPW╜130╛30⌐G╜V[2]+79⌡V[2]=0'                                        °
  614.   'L1:╕((1<╧W)doif ''''''W╜∞0'''' ÉEA ''''W╜πW'''''')/L1'                      °
  615.   '╕(((0=µεW)δ2<µµW)doif ''U╜(~V╧4╞0)/M'')/0'                                  °
  616.   'T╜(1≥µµU╜«W)doif ''U╜πW╜(U⌠'''' '''')ΓU'''                                  °
  617.   'T╜(0<V[1])doif ''U╜(«(Φ1,╞µW)µ(V[3]µ'''' ''''),∞(╞µW)-V[3]),'''' ''''       °
  618.  ,U''' '╕(G<30)/0' 'T╜(F╜µεV[4])+C╜1╟B╜µA╜(V[3],0)╟U'                          °
  619.   'T╜⌐(1╞B)÷1⌐╛(ÉPW+F)÷T' 'U╜(E╜(V[3],C)╞U),[1](B╜T,1╟B)╞A'                    °
  620.   '''D╜εV[4]'' ÉEA ''D╜ÉAV[εV[4]+33⌡V[4]=0]''' 'L0:A╜(T,0)╟A'                  °
  621. X '╕(0=1╞µA)/0' 'U╜U,(((T+V[3]),µD)µD),E,[1]B╞A' '╕L0'                         °
  622. *(1997 7 13 12 28 59 544)                                                      °
  623.  Ftest ÉFX 'U╜V test W;P'                                                      °
  624.   'Σ Describe problem in W, (correct answer in V)' 'U╜2' 'L1:W'                °
  625.   'É╜''      ''' 'P╜æ' '''╕L0'' ÉEA ''P╜»P''' '╕(V╧P)/0'                       °
  626. X 'L0:╕(0=U╜U-1)/0' '''Incorrect. Try again''' '╕L1'                           °
  627. XCuc 1 26 ABCDEFGHIJKLMNOPQRSTUVWXYZ                                           °
  628. *(1997 8 21 13 15 13 348)                                                      °
  629.  Fupdate ÉFX 'update'                                                          °
  630.   '''This version of APL2 lessons has been updated in the summer of 1997       °
  631.  '''                                                                           °
  632.   '''Any subsequent updates will be announced to the APL news group.'''        °
  633.   '''You may also e-mail me at jizba@kaiwan.com for additional details.'       °
  634.  '' '''Any constructive comments will be welcome.'',r'                         °
  635.   '''For an update of these lessons, mail a self addressed stamped'''          °
  636.   '''floppy disk mailer with two HD 3.5 inch blank floppies to:'',r'           °
  637.   '''                  Zdenek V. Jizba'''                                      °
  638.   '''                  1341 Rebecca Dr.'''                                     °
  639. X '''                 La Habra, CA 90631'''                                    °
  640. *(1996 4 6 16 11 57 440)                                                       °
  641.  Fvec ÉFX 'U╜V vec W;T' 'Σ Draw 2d vector in plane'                            °
  642.   'T╜(0=ÉNC ''V'')doif ''V╜'''''''''''                                         °
  643.   'U╜r,'' '',W[3],r,''2-        +'',W[2],r '':      °'',r,''1-    °'',r'       °
  644. X 'U╜U,'' :  °'',r,''0|....|....|.'',V,,'' '',W[1],r,'' 0    1    2'',r'       °
  645.