From: Eric S. Raymond Date: Thu, 1 Apr 2004 16:07:48 +0000 (+0000) Subject: Before sectioning out equation. X-Git-Tag: 1.0~35 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=0b30d6dc3845d4768f1aa379b808d546087428c4;p=mad.git Before sectioning out equation. --- diff --git a/doc/mad-manual.xml b/doc/mad-manual.xml index eea0b4c..63d6ed5 100644 --- a/doc/mad-manual.xml +++ b/doc/mad-manual.xml @@ -3965,7 +3965,76 @@ there is no general way to implement this in generated C. Example 7<emphasis role='note'>: Solve simultaneous linear equations</emphasis> - +Problem Solve a system of n ≤ 20 simultaneous +linear equations in n unknowns, assuming that one does not encounter a +zero on the main diagonal of the coefficient matrix during the +solution process. + +Analysis: We shall use a Jordan Elimation [typo?] +Method, in which each diagonal coefficient is used to "clear" all +other coefficients in its column to zero by appropriate +multiplications and subtractions. Since we shall divide the "clearing +row" by the diagonal element in that row before clearing t;he column, +we shall finish the process with only a diagonal of ones and the +solution to the problem as the resulting right hand side of the +equations. + +We denote the system of equations to be solved by: + + + a11x1 + a12x2 + ... + a1nxn = a1,n+1 + +(1) a21x11 + a22x2 + ... + a2nxn = a2,n+1 + + . . . . + . . . . + . . . . + an1x1 + an2x2 + ... + annxn = an,n+1 + + +We divide the first row by its diagnoal element +a11. Then to clear a21 +ato zero we substract a21 times the first row +from the second row, and so on. In general, to clear +aik to zero (after row K has been divided by +akk), we subtract aik +times row k from row i (i≠k). A typical element +aij is thus transformed each time by the +formulas: + + +(2) akj = akj/akk + +(3) aij = aij-aikakj (i≠k) + + +where the value of akj in (3) is the result of +(2). These transformations are performed for k = 1, 2, ..., n. For +each (fixed) k, we will let i = 1, 2, ...., k-1, k+1, ..., n, so as to +operate on all rows except i=k. While transforming each row we will +cycle on j from right to left; i.e., j = n+1, n, n-1, ... k, and we +stop at j = k since for j < k there is no change in the matrix. + + +The array + + + a11a12 ... a1,n+1 + . . + . . + A = (aij) = . . + . . + an1an2 ... an,n+1 + + +is called the "matrix of coefficients" of the system (1). + +It should be understood that this method, involving the assumption of +no zeros on the diagonal and not searching for the largest element of +a row to use as a divisor (to minimize round-off error), is not +satisfactory from a mathematical point of view. It could serve as a +basis for a larger, more complete program, however, and serves here +only as an example problem. Flow diagram: @@ -3995,11 +4064,92 @@ there is no general way to implement this in generated C. Business Data Processing Examples Example 1<emphasis role='note'>: Payroll Processing</emphasis> - +Problem: Compute the social security deduction +and accumulated gross pay. The program should read a card containing: +(a) the employee's name, (b) his payroll number, (c) his gross pay for +the current week, and (d) his accumulated gross pay for the current +year (but not including item (c)). For each card read, the program +should print (a) and (b) from the card, and, in addition, print (e) +the updated gross pay, (f) the social security deduction for the +current week, and (g) the net pay for the current week, taking into +account only the social security deduction. + +Analysis: The social security deduction is +currently 3% of the gross pay until the accumulated gross pay for the +year exceeds from $4800.00. The updated gross pay can be computed +from the formula, (e) = (c) + (d). The social security deduction has +already been made on (d). There are thus three cases to consider: - -Flow diagram: + +(d) ≥ 4800.00, in this case (f) = 0. +(d) < 4800.00 and (c) + (d) > 4800.00, +in this case (f) = 3% of 4800.00 - (d) +(c) + (d) > 4800.00, +in this case f = 3% of (c). + + +The information on the cares to be read will be in the following +format: + + + +Card ColumnsInformation + + +1-30(a) employee's name +31-38(b) payroll number +39-44(c) gross pay for the current week in the form XXX.XX +45-52(d) accumulated gross pay for the current year in the form XXXXX.XX + + + + +The printed output will be in the following format: + + + + + +Line ColumnsInformation + + +Line ColumnsInformation +1Carriage control for printer +2-31(a) employee's name +32-34Blank +35-42(b) payroll number +43-45Blank +46-53(e) updated gross pay for current year in the form XXXXX.XX +54-56Blank +57-61(f) social security deduction for current week in the form XX.XX +62-64Blank +65-70(g) net pay for current week in the form XXX.XX + + + + +Flow chart: We will use the following +abbreviations: + + + + +NAMEfor employee's name (a). +PAYNRfor payroll number (b). +GROSSWgross pay for current week (c). +AGROSYaccumulated gross pay for current year (d). +UGROSYupdated gross pay for current year (e) +FICAsocial security deduction for current week (f). +NET PAYnet pay for current week (g). + + + + + +  + + @@ -4033,14 +4183,94 @@ JAMES MADISON 12345681 200. 4700. JOHN QUINCY ADAMS 12345682 100. 300. - - + +Notes on these programs: + +1. The maximum number of characters which can be stored in one machine +word is six. Hence, we need five machine words to store the 30 +characters allowed for the employee's name. We need to give a +dimension declaration stating that NAME is actually be a block and +that NAME(5) is the last word of this block. In the read and print +statements we specify that the whole block is to be read or printed by +writing NAME(1) ... NAME(5) and giving the format specification 506, +i.e., 5 words of 6 characters. + +2. Since the payroll number is an integer (i8, i.e., and 8 digit +integer) we give an integer mode declaration stating that PAYNR is an +integer. Similarly, since alphabetic information is assumed to be in +the integer mode, NAME is also declared to be integer. + + Example 2<emphasis role='note'>: Payroll Tape Processing</emphasis> +Problem: Assume that a master tape is available containing basic +information for each employee: (1) The employee number, (2) his hourly +rate, (3) gross pay to date, (4) amount of withholding tax withheld to +date, (5) social security deduction withheld to date, (6) net pay to +date, and (7) the number of exemptions. Input will be in the form of +m cards representing the current pay record, containing the employee's +number and the number of hours worked during the current week. Pay is +to be copmuted at time and a half for any hours worked over forty. +(We shall assume that the input deck is already sorted according to +increasing employee number, but we shall provide for cards which may +be out of order. The last input card must have an employee number +greater than the last employee number of the master tape. + +The withholding tax W is to be computed by the formula: + +W = .18(Gross pay = 13 n) + +where n is the number of exemptions. If n is negative, we set W += 0 (see Note 2 below). The social security deduction FICA is 3 per +cent of gross pay up to $4800, with no deduction for gross pay over +$4800. + +A program is desired which will produce a listing (for each input +card) of (a) employee number, (b) gross pay this week, (c) withholding +tax, (d) FICA, (e) net pay for the week. Moreover, a new updated +master tape shojuld be prepared, with provision for saving the +previous master tape as well. As much checking as possible should be +incorporate, including specifying to the operator the number of the +master tape needed, and the number to be assigned to the new tape +produced by the program, and the automatic checking that the correct +tape has been mounted on the unit. + +Note 1: Abbreviations used here are outlined in Example 1, +except for the following new terms: + + + + + +AWITHYaccumulated withholding tax for year +AFICAYaccumulated social security deduction for year +ANETYaccumulated net pay for year. +EXEMPTno. of exemptions + + + + +Note 2: In the computations of the gross pay for the current week we +shall find it useful to be able t5o compute a function (which we shall +call EXCESS.) of two numbers, say a and b, whose value is 0 if a ≤ b, +and a-b if a > b. A formula for this function is + +EXCESS.(a,b) = a - b + |a - b| / 2, + +where | | denotethe usual "absolute value". In fact, by using +this function, a simple one-line formula for this function is: + +FICA = .03 EXCESS.((GROSSW - EXCESS.(AGROSY, 4800.)),0) + +where AGROSY is assumed to already contain GROSSW, i.e., to have +been updated already. We shall also apply this function in the case +of the withholding tax to guarantee that we do not make a negative +deduction. +