home *** CD-ROM | disk | FTP | other *** search
/ Outlet 51 / outlet-51.mgt / c5 < prev    next >
Text File  |  2021-04-18  |  20KB  |  1 lines

  1.         Pafnuti Chebyshev was a nineteenth-century Russian      mathematician who devised a method for calculating any function to any required degree of approximation by using polynomials in this way. To explain the method in full, even if I knew how to, would take rather a lot of space, but references are given under3449 series-06 and on page 226 of the notes_(Handbook_of        _Mathematical_Functions by M Abramowitz and I A Stegun, Dover   1965, especially pages 82 and 795).                                     The method uses a standard series of_Chebyshev          _polynomials, polynomials whose coefficients are the same       whatever the function being approximated, and hence called      _Chebyshev_coefficients; and it also finds a set of_Chebyshev   _constants which are special to the particular function.                The expansion at the bottom of page 227 of the notes    shows the first twelve Chebyshev polynomials and their Chebyshevcoefficients; the way the coefficients run in the standard      polynomials - they are the same for any function - is a little  easier to follow if you tabulate them by themselves, leaving outall the zs, plus and minus signs, etc:                                                                                                     2048  5632  5632  2464   440    22                              1024  2560  2240   800   100     2                               512  1152   864   240    18                                     256   512   320    64     2                                     128   224   112    14                                            64    96    36     2                                            32    40    10                                                  16    16     2                                                   8     6                                                         4     2                                                         2                                                               2 (This last 2 isn't used as a coefficient)                                                                               You will find, if you check it, that each number in thistable is                                                               the sum of all the numbers below it in its own column,          plus all the numbers in the previous column, starting    from two below it.                                                      Also you can see from the expansion on page 227 of the  notes that in each of the Chebyshev polynomials                        - the powers of z are all odd for the first, third, fifth... polynomial and all even for the second, fourth, sixth ...          - the coefficients in each polynomial have alternately + and - sign, always starting with +.                                     All this is expressed mathematically by the "recurrence relation" given in the header to 3449 series-06 on page 198                   T(n+1)(z) = 2*z*T(n)(z) - T(n-1)(z)                or in words, each Chebyshev polynomial after the first three is2z times the last one minus the one before that. See also the   index under 3449 series-06.                                             Using either the table or the recurrence relation, you  can figure for yourself any number of Chebyshev polynomials. Youwould have to know that the first three are Y = 1 and Y = 2z andY = 4z**2 - 2.                                                          To get the final approximation for the function of z youcalculate as many polynomials in the series as you require and  multiply each of them by the correct constant in the series for the particular function; then you add all these products        together for the result.                                                The Chebyshev constants are different for each function of z: the correct constants for each ROM function are shown in  decimals in the BASIC demo programs on pages 223-226 of the     Appendix, and in FP form in the various calls to series-06; bothversions have been copied in this index under the function      subroutines concerned.                                                  The method by which the constants are calculated is     indicated in the footnotes on pages 223-226, not very clearly;  and it is also not clear whether this method can be generalized to other functions, or if so how.                                       The approximations based on Chebyshev polynomials as    used by the Spectrum ROM don't depart from the curves they are  mimicking by more than about one in ten million, say six inches in a thousand miles, within the range in which they are used;   outside this range Pafnuti rapidly loses control, and they may  diverge quite far quite quickly.                                        The same SERIES GENERATOR procedure can be used for any function at all; provided you are clever enough to figure out   the right constants for your function!                                  Introduction used for SIN, exp, ln, atn                         36C4 EXP used                                                   3713 ln used                                                    37BF sin used                                                   37E2 atn used                                                   Appendix BASIC demonstration programs                                                                                       CHECK END subroutine 1BEE                                           Called for syntax checking when the end of a command    statement ought to have been reached. Only executed during      syntax checking; in run time, it returns immediately.                   In syntax checking it reports "Nonsense in BASIC" if it doesn't find a statement "terminator"; if it does, it drops a   return address to make a "double return" to the statement loop.         All the calls are from subroutines executing BASIC      commands, or from the command class routines subordinate to     them, listed in the parameter table at 1A7A.                            None of these command routines are called in a          straightforward way: they are all entered by the computed       indirect jump from 1B55 GET PARAM, which is within the          "statement loop". This loop is itself part of the subroutine    1B8A LINE RUN, but for syntax checking it is also entered from  1B17 LINE SCAN, called from main execution by 12AC MAIN 2.              Thus on entry to this CHECK END subroutine the addresseson the machine stack are                                               - top: the return address to the calling subroutine. The notes are mistaken in saying that 1B52 SCAN LOOP stacked by 1B55GET PARAM is dropped in CHECK END; it has been dropped already  either in 1C11 CLASS 05 or in the calling routine                      - second: 1B76 STMT RET put here by 1B29 STMT L 1, the   looping address of the LINE SCAN loop                                  - third: return address to 12AC MAIN 2.                         Input parameters: none.                                         Action: if the flag indicates "run time" return                  - drop the return address.                                     Exit: into 1BF4 STMT NEXT; it returns to 1B76 STMT RET.         Output parameters: none                                          - the return address is now 12AC MAIN 2.                       Called from:                                                    (0605 SAVE ETC from 1CDB CLASS 0B:)                              0692 SA DATA 1                                                  06A0 SA SCR$                                                    06F9 SA CODE 4                                                  0716 SA LINE                                                    0723 SA LINE 1                                                 (17F9 LIST:)                                                     1822 LIST 5                                                    (direct from CLASS routines:)                                    1C11 CLASS 05                                                   1C4E CLASS 02                                                   1C96 PERMS                                                     (1D03 FOR:)                                                      1DO3 FOR                                                        1D10 F USE 1                                                   (1DED READ:)                                                     1E1E READ 2                                                    (1E27 DATA:)                                                     1E2C DATA 1                                                    (1F60 DEF FN:)                                                   1FBD DEF FN 7                                                  (1FCD PRINT:)                                                    1FCF PRINT 1                                                   (2089 INPUT:)                                                    2096 INPUT 1                                                   (2320 CIRCLE:)                                                   2320 CIRCLE                                                    (2382 DRAW:)                                                     2382 DRAW                                                       238D DR 3 PRMS                                                 (2C02 DIM:)                                                      2C05 D RPORT C                                                                                                              checking syntax see errors                                                                                                      CHR$ key (C2) see also commands, functions and operators,   KEYBOARD SCANNING, 022C extended mode table (b)                         The U key in E mode without shift produces the function CHR$; it requires one numeric operand X, less than 256d, and thevalue of the function is the character whose code is INT X.             On execution, 24FB SCANNING quickly leads to 26DF S     NEGATE. This converts the key code C2 first to 13h, then to EF, and adds the priority 10h/16d. Code and priority 10EF are now   pushed on to the machine stack (270D S PUSH PO) while the       expression following CHR$ is evaluated.                                 When the code is taken off the stack (2734 S LOOP), it  is converted (2773 S TIGHTER) from EF to 2F, the calculator     offset for 35C9 chr$.                                                   2707 S NO TO $ number result from string argument                                                                           chr$ subroutine 35C9                                                Called from 0028 FP CALC with the literal 2F; the       executive routine of the CHR$ function. Not called otherwise    from ROM. Could be called from m/c direct, to convert a         character code X to a character.                                       Input parameters: X must be the last value on the        calculator stack, even for direct calls; it needn't be an       integer, but must be positive and less than 256d.                      Action: call 2DD5 FP TO A to get the number in A                 - if it returns with carry or NZ report "Integer out of range"; either negative or too big                                      - call 0030 BC SPACES to make a space in the work space         - put the character code in it                                  - call 2AB2 STK STORE to put the string parameters of   this single character on the calculator stack.                         Exit: RET.                                                      Output parameters: the last value on the calculator stackis now the string parameters of a single character, code X, in  the work space                                                          - HL and DE point respectively to the last value and to the stack end.                                                                                                                      CIRCLE key (D8) see also commands, functions and operators, KEYBOARD SCANNING, 0246 extended mode key table (c)                     The H key in E mode with either shift produces the      command CIRCLE. It must be followed by three parameters X, Y, z;X and Y are the pixel coordinates of the centre of the circle   and z the radius in pixels.                                             The command is read by 1B29 STMT L 1 referring through  the syntax offset table 1A48 to the syntax parameter table 1A7A.1AE7 P CIRCLE causes jumps via 1C16 JUMP C R to                        1CBE CLASS 09 which handles any colour controls and gets X and Y                                                                1C11 CLASS 05 which merely checks syntax                  and to the executive routine 2320 CIRCLE.                                                                                          CIRCLE subroutine 2320                                              Called only from the statement loop by 1AE7 P CIRCLE in the syntax parameter table; executes the CIRCLE X,Y,Z command.  See the BASIC model in the Appendix of the notes, page 228.             Cannot easily be called direct from m/c, because it is  normally entered with only the first two parameters on the stackand begins by reading the radius Z from BASIC. M/c programmers  should call 232D (RST 28 FP CALC) with all three parameters on  the calculator stack, Z as last value.                                  The radius Z is put on the stack and re-stacked as a    full-form FP number; its sign is ignored. If the radius is less than one, the circle is just plotted as a point at X,Y.                 Now call 247D CD PRMS1, with 2pi in mem-5 as the value  of G, the angle through which the line drawn is to turn. It     returns the arc count a and SIN pi/a. The arc count is the      number of "arcs" to be drawn to approximate the circle, and Z   times SIN pi/a is half the length of each arc in pixels; there  is a misprint here in the notes. Other parameters are returned, but not used till the exit routine. If the arc length is less   than one, again the circle is plotted as a point.                       The rest of the routine prepares parameters for the exitroutine 2420 DRW STEPS, which actually draws the circle:               - the coordinates sa, sb of the start point of the DRAW: sa = Z + X, directly to the right of the centre and at the      distance of the radius, sb = Y - Z SIN pi/a, half an arc length directly below the level of the centre                                 - the coordinates of the end point: in the case of a     circle the start point is also the end point                           - the displacements in the x and y direction of the firstarc to be drawn: this will be vertically upwards to the level ofthe centre and the same distance beyond, so the x displacement  is zero and the y displacement is 2Z SIN pi/a.                          X, Y, Z and Z SIN pi/a are already on the stack, and it is simple to calculate sa, sb, and 2Z SIN pi/a. The arc count a is also already on the machine stack.                                  Input parameters: X and Y must be the last two items on  the calculator stack, even for direct calls. The BASIC pointer  in 5C5D CH ADD points to the comma after Y.                            Action: read the BASIC                                           - if the code isn't a comma report "Nonsense in BASIC"          - move the pointer on                                           - call 1C82 EXPT 1NUM to evaluate the expression for Z          - call 1BEE CHECK END; this must be the end of the      statement                                                               - use the calculator to get ABS Z and re-stack it as a  full-form FP number                                                     - check the exponent of Z                                       - if it is more than 80h jump on to C R GRE 1; Z is one or more                                                                 - (Z < 1) delete Z from the stack                               - exit to 22DC PLOT; the circle is just plotted as a    point at X, Y.                                                         _233B_C_R_GRE_1: use the calculator to get pi/2 from the table of constants                                                      - change its exponent to 83h; making it 2pi                     - put 2pi in mem-5                                              - call 247D CD PRMS1 to calculate the "input parameters for CIRCLE and DRAW", the arc count and the various functions ofG; here G = 2pi                                                         - save the arc count on the stack                               - get SIN pi/a from mem-1 and multiply it by Z; this is half the arc length                                                     - if its exponent is 80h or more jump on to C ARC GE1;  the arc half-length is more than half                                   - (arc length < 1) delete the arc half-length                   - exit to 22DC PLOT; the circle is just plotted as a    point at X, Y.                                                         _235A_C_ARC_GE1: use the calculator to figure sb = Y - Z SIN pi/a and sa = Z + X                                                 - by duplicating, exchanging and use of mem-0, make the stack hold, from the top, sa, sb, sb, sa, sb, sa                        - put zero in mem-1 for the exit routine                        - increment the exponent of mem-2; doubling the arc     half-length so it is now the length required by the exit        routine. [The listing shows "INC (mem-2-1st)" but the machine   code actually reads "INC (IY+62h)": since MEMBOT is IY+58h, the byte incremented is the tenth in memory, ie the first byte of   the third 5-byte number, the exponent byte of mem-2.]                   - call 1E94 FIND INT1 twice to take the top two values  sa and sb off the stack                                                 - put them in 5C7D COORDS for the exit routine                  - recover the arc count for the exit routine.                  Exit: into 2420 DRW STEPS to draw the circle, or                 - into 22DC PLOT if the radius is zero or the arc lengthis too small.                                                          Output parameters: B holds the arc count                         - the parameters for PLOT or DRW STEPS are left in      memory locations and on the calculator stack                            - corrupts all memory locations mem-0 -> mem-5.                Rems:                                                            22DC PLOT used twice by                                         2420 DRW STEPS angle of arc is 2pi                              247D CD PRMS1 called by with X Y Z on stack                     Appendix: BASIC demo program                                                                                                CL ADDR subroutine 0E9B                                             Finds the screen display address of the first pixel of agiven screen line number, counted from one at the bottom of the screen to 18h/24d at the top. Can be called from m/c.                   Each "third" of the screen starts at an address with 00 in its lo byte: 4000, 4800 and 5000; the eight line starts in   each third have lo bytes 00, 20h, 40h ... E0h. See DISPLAY AREA.        Divide the screen line number counted from zero at the  _top of the screen by 8, giving a quotient q with remainder r.          Then the hi byte of the display address will be 40h + 8q       - and the lo byte will be the r'th of the line start     bytes, r times 20h.                                                     The ROM is a good example of "one-byte binary           arithmetic", see the index entry for others.