]> thyrsus.com Git - mad.git/commitdiff
Before sectioning out equation.
authorEric S. Raymond <esr@thyrsus,com>
Thu, 1 Apr 2004 16:07:48 +0000 (16:07 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Thu, 1 Apr 2004 16:07:48 +0000 (16:07 +0000)
doc/mad-manual.xml

index eea0b4c5d26b5ae0dac1c4ead57b4ba48519db0a..63d6ed5c0f579206abc3771ae6a2843b052aec0d 100644 (file)
@@ -3965,7 +3965,76 @@ there is no general way to implement this in generated C.</para></note>
 <!-- beginpage III.19 -->
 <sect2><title>Example 7<emphasis role='note'>: Solve simultaneous linear equations</emphasis></title>
 
-<!-- FIXME: TEXT FOR PAGES III.19-20 GOES HERE -->
+<para><emphasis>Problem</emphasis> Solve a system of n &le; 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.</para>
+
+<para><emphasis>Analysis</emphasis>: 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.</para>
+
+<para>We denote the system of equations to be solved by:</para>
+
+<programlisting>
+         a<subscript>11</subscript>x<subscript>1</subscript> + a<subscript>12</subscript>x<subscript>2</subscript>  + ... + a<subscript>1n</subscript>x<subscript>n</subscript> = a<subscript>1</subscript>,n+1
+
+(1)      a<subscript>21</subscript>x<subscript>11</subscript> + a<subscript>22</subscript>x<subscript>2</subscript> + ... + a<subscript>2n</subscript>x<subscript>n</subscript> = a<subscript>2</subscript>,n+1
+
+           .       .             .        .
+           .       .             .        .
+           .       .             .        .
+       a<subscript>n1</subscript>x<subscript>1</subscript>  + a<subscript>n2</subscript>x<subscript>2</subscript> + ...  + a<subscript>nn</subscript>x<subscript>n</subscript> = a<subscript>n</subscript>,n+1
+</programlisting>
+
+<para>We divide the first row by its diagnoal element
+a<subscript>11</subscript>.  Then to clear a<subscript>21</subscript>
+ato zero we substract a<subscript>21</subscript> times the first row
+from the second row, and so on.  In general, to clear
+a<subscript>ik</subscript> to zero (after row K has been divided by
+a<subscript>kk</subscript>), we subtract a<subscript>ik</subscript>
+times row k from row i (i&ne;k).  A typical element
+a<subscript>ij</subscript> is thus transformed each time by the
+formulas:</para>
+
+<programlisting>
+(2)      a<subscript>kj</subscript> = a<subscript>kj</subscript>/a<subscript>kk</subscript>
+
+(3)      a<subscript>ij</subscript> = a<subscript>ij</subscript>-a<subscript>ik</subscript>a<subscript>kj</subscript>  (i&ne;k)
+</programlisting>
+
+<para>where the value of a<subscript>kj</subscript> 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 &lt; k there is no change in the matrix.</para>
+<!-- beginpage III.20 -->
+
+<para>The array</para>
+
+<programlisting>
+                       a<subscript>11a</subscript><subscript>12</subscript> ... a<subscript>1</subscript>,n+1
+                            .          .
+                            .          .
+       A = (a<subscript>ij</subscript>)    =       .          .
+                            .          .
+                       a<subscript>n1a</subscript><subscript>n2</subscript> ... a<subscript>n</subscript>,n+1
+</programlisting>
+
+<para>is called the "matrix of coefficients" of the system (1).</para>
+
+<para>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.</para>
 
 <!-- beginpage III.21 -->
 <para><emphasis>Flow diagram:</emphasis></para>
@@ -3995,11 +4064,92 @@ there is no general way to implement this in generated C.</para></note>
 <sect1><title>Business Data Processing Examples</title>
 <sect2><title>Example 1<emphasis role='note'>: Payroll Processing</emphasis></title>
 
-<!-- FIXME: TEST FOR PAGES III.24-25 GOES HERE -->
+<para><emphasis>Problem:</emphasis> 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.</para>
+
+<para><emphasis>Analysis:</emphasis> 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:</para>
 
-<!-- beginpage III.26 -->
-<para role='note'><emphasis>Flow diagram:</emphasis></para>
+<orderedlist>
+<listitem><para>(d) &ge; 4800.00, in this case (f) = 0.</para></listitem>
+<listitem><para>(d) &lt; 4800.00  and (c) + (d) &gt; 4800.00, 
+in this case (f) = 3% of 4800.00 - (d)</para></listitem>
+<listitem><para>(c) + (d) &gt; 4800.00, 
+in this case f = 3% of (c).</para></listitem>
+</orderedlist>
+
+<para>The information on the cares to be read will be in the following
+format:</para>
 
+<informaltable>
+<tgroup cols='2'>
+<thead>
+<row><entry><emphasis>Card Columns</emphasis></entry><entry><emphasis>Information</emphasis></entry></row>
+</thead>
+<tbody>
+<row><entry>1-30</entry><entry>(a) employee's name</entry></row>
+<row><entry>31-38</entry><entry>(b) payroll number</entry></row>
+<row><entry>39-44</entry><entry>(c) gross pay for the current week in the form XXX.XX</entry></row>
+<row><entry>45-52</entry><entry>(d) accumulated gross pay for the current year in the form XXXXX.XX</entry></row>
+</tbody>
+</tgroup>
+</informaltable>
+
+<para>The printed output will be in the following format:</para>
+<!-- beginpage III.25 -->
+
+<informaltable>
+<tgroup cols='2'>
+<thead>
+<row><entry><emphasis>Line Columns</emphasis></entry><entry><emphasis>Information</emphasis></entry></row>
+</thead>
+<tbody>
+<row><entry><emphasis>Line Columns</emphasis></entry><entry><emphasis>Information</emphasis></entry></row>
+<row><entry>1</entry><entry>Carriage control for printer</entry></row>
+<row><entry>2-31</entry><entry>(a) employee's name</entry></row>
+<row><entry>32-34</entry><entry>Blank</entry></row>
+<row><entry>35-42</entry><entry>(b) payroll number</entry></row>
+<row><entry>43-45</entry><entry>Blank</entry></row>
+<row><entry>46-53</entry><entry>(e) updated gross pay for current year in the form XXXXX.XX</entry></row>
+<row><entry>54-56</entry><entry>Blank</entry></row>
+<row><entry>57-61</entry><entry>(f) social security deduction for current week in the form XX.XX</entry></row>
+<row><entry>62-64</entry><entry>Blank</entry></row>
+<row><entry>65-70</entry><entry>(g) net pay for current week in the form XXX.XX</entry></row>
+</tbody>
+</tgroup>
+</informaltable>
+
+<para><emphasis>Flow chart:</emphasis> We will use the following
+abbreviations:</para>
+
+<informaltable>
+<tgroup cols='2'>
+<tbody>
+<row><entry>NAME</entry><entry>for employee's name (a).</entry></row>
+<row><entry>PAYNR</entry><entry>for payroll number  (b).</entry></row>
+<row><entry>GROSSW</entry><entry>gross pay for current week (c).</entry></row>
+<row><entry>AGROSY</entry><entry>accumulated gross pay for current year (d).</entry></row>
+<row><entry>UGROSY</entry><entry>updated gross pay for current year (e)</entry></row>
+<row><entry>FICA</entry><entry>social security deduction for current week (f).</entry></row>
+<row><entry>NET PAY</entry><entry>net pay for current week (g).</entry></row>
+</tbody>
+</tgroup>
+</informaltable>
+
+<!-- Bogus presentation-level hack to keep the table and diagram apart -->
+<para>&nbsp;</para>
+
+<!-- beginpage III.26 -->
 <mediaobject>
   <imageobject>
     <imagedata fileref='fig14.png'/>
@@ -4033,14 +4183,94 @@ JAMES MADISON                            12345681 200.    4700.
 JOHN QUINCY ADAMS                        12345682 100.     300.
 </programlisting>
 
-</sect2>
 <!-- beginpage III.29 -->
 
-<!-- FIXME: TEXT FOR PAGES III.29 GOES HERE -->
+<!-- This was an unnumbered section in the original -->
+<sect3><title>Notes on these programs:</title>
+
+<para>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.</para>
+
+<para>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.</para>
+</sect3>
+</sect2>
 
 <!-- beginpage III.30 -->
 <sect2><title>Example 2<emphasis role='note'>: Payroll Tape Processing</emphasis></title>
 
+<para>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.</para>
+
+<para>The withholding tax W is to be computed by the formula:</para>
+
+<para role='centered'>W = .18(Gross pay = 13 n)</para>
+
+<para>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.</para>
+
+<para>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.</para>
+
+<para>Note 1: Abbreviations used here are outlined in Example 1,
+except for the following new terms:</para>
+<!-- beginpage III.31 -->
+
+<informaltable>
+<tgroup cols='2'>
+<tbody>
+<row><entry>AWITHY</entry><entry>accumulated withholding tax for year</entry></row>
+<row><entry>AFICAY</entry><entry>accumulated social security deduction for year</entry></row>
+<row><entry>ANETY</entry><entry>accumulated net pay for year.</entry></row>
+<row><entry>EXEMPT</entry><entry>no. of exemptions</entry></row>
+</tbody>
+</tgroup>
+</informaltable>
+
+<para>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 &le; b,
+and a-b if a &gt; b.  A formula for this function is</para>
+
+<para role='centered'>EXCESS.(a,b) = a - b + |a - b| / 2,</para>
+
+<para>where | | denotethe usual "absolute value".  In fact, by using
+this function, a simple one-line formula for this function is:</para>
+
+<para role='centered'>FICA = .03 EXCESS.((GROSSW - EXCESS.(AGROSY, 4800.)),0)</para>
+
+<para>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.</para>
+
 <!-- FIXME: TEXT FOR PAGES III.30-32 GOES HERE -->
 
 <!-- beginpage III.33 -->