Riemann for the HP 48G(X)


The following is in the Hewlett Packard ASCII format used by hp link and other hp datainterchange programs.  There are four issues that you should be aware of if you areattempting to type this program into your calculator 'by hand':

  1. The first line of the program contains identification information that is used internally by the calculator.  It is should be omitted if you are entering the program 'by hand'.  Thus, as usual, in entering the program by hand, the first keystroke should produce the '<<' '>>' character.pair.
  2. Non-ASCII characters are 'escaped'; i.e., preceded by the backslash character.  For instance, the 'store as parameters' symbol (a simple right directed arrow wpe3.jpg (752 bytes)) is denoted by '\->', the 'store as a list' command, wpe4.jpg (988 bytes), is denoted by '\->LIST', and the double angle brackets that enclose a program are denoted by '\<<' and '\>>'.  \GSLIST denotes the 'sum list term by term' function, wpe2.jpg (1010 bytes), found in MTH/LIST.  The 'to tag' function, wpe5.jpg (995 bytes), is denoted by  \->TAG.   Finally, the '|' (often found on the shifted '\' key on computer keyboards) is the 'evaluate at' function.
  3. The ampersand ('@') always marks the beginning of a comment.  Within any line of the program, all of the text that lies to the right of an ampersand character will be ignored when the program is compiled.  Since comments are not executed, they can all be omitted when entering the program 'by hand'.
  4. The hp48G(X) parser is context-free; none of the of the program's 'white space' formatting has any effect on its execution.  In particular, the indenting of lines in the display below is done purely for readability.  It can be omitted without affecting the program's correct operation.

THIS PROGRAM HAS NOT BEEN PLACED IN THE PUBLIC DOMAIN.  IN UNALTERED FORM, IT CAN BE USED FOR ANY NON-COMMERCIAL EDUCATIONAL PURPOSE.  THECODE GIVEN BELOW SHOULD NOT BE MODIFIED IN ANY WAY WITHOUT THEWRITTEN PERMISSION OF THE AUTHOR.  IF YOU USE ANY PART OF THE CODE OR ANY OF THEIDEAS WORKED OUT WITHIN IT, THE COPYRIGHT NOTICE INCLUDED IN THIS PROGRAM MUSTBE DISPLAYED AT YOUR PROGRAM'S STARTUP.


%%HP: T(3)A(D)F(.);\<< CLLCD    @    "HP 48G(X) RIEMANN SUMS" 2 DISP    @    "   Copyright (c) 1996"  4 DISP    "     by Jack Courtney"  5 DISP    "   All Rights Reserved" 6 DISP    @    @ Calculate a Riemann sum for an arbitrary function, over an arbitrary real interval,    @   by using an arbitrary number of subintervals.    @    @  Varieties of sums available: left hand    @                               right hand    @                               trapezoidal    1 @ 1/0: plotting is on/off    { "Left Hand"      "Right Hand"      "Trapezoidal"    @ "Maximal"    @ "Minimal"    }    \-> plot choices    \<< 0        WHILE 0 ==        REPEAT            440 0.01 BEEP            "CHOOSE SUM TYPE" choices 1 CHOOSE        END        choices OVER POS        \-> choice        \<< " Sum" +              @ Push the INFORM title onto the stack            VARS 'EQ' POS         @ Push the list of INFORM rset values onto the stack            IF 0 ==            THEN {NOVAL}            ELSE RCEQ            END            VARS 'PPAR' POS            IF 0 ==            THEN {NOVAL 10 NOVAL NOVAL}            ELSE PPAR 3 GET                 10                 PPAR 1 GET RE                 PPAR 2 GET RE                 4 \->LIST            END            +            \-> title rset            \<< 0                WHILE 0 ==                REPEAT                    title                                                   @ Title                    { { "EQ:"    "ENTER INTEGRAND"                  6 8 9 }                      {                                                   } @ Large entry field                      { "Indep:" "ENTER INTEGRATION VARIABLE NAME"    6 9 } @ Small entry field                      { "Subs:"  "ENTER INTEG. VAR. SAMPLE COUNT"       0 } @ Small entry field                      { "H-Min:" "ENTER MIN. VALUE FOR INTEG. VAR."     0 } @ Small entry field                      { "H-Max:" "ENTER MAX. VALUE FOR INTEG. VAR."     0 } @ Small entry field                    }                    { 2 0 }                                               @ {cols,tabs}                    rset                          @ rset values                    VARS 'RPAR' POS               @ init values                    IF 0 ==                    THEN rset                    ELSE RPAR                    END                    440 0.01 BEEP                    IFERR                        INFORM                    THEN                        "Illegal values in EQ, PPAR or RPAR. Please purge these vars." MSGBOX                        5 DROPN KILL                    END                    SWAP                          @ SAVE rc                    DUP 'RPAR' STO                @ Output is RPAR                    LIST\-> DROP                    DUP2                          @ Test Hmin and Hmax                    IF \>=                    THEN                        CLEAR 0                   @ Change rc to 0                        "ERROR: H-max >= H-min" MSGBOX                    ELSE                        DUP2 IF > THEN SWAP END XRNG  @ Set XRNG in PPAR                        DROP INDEP                    @ Set Indep in PPAR                        'EQ' STO                      @ Set EQ                    END                END            \>>            IF plot            THEN                ERASE                FUNCTION                AUTO                @ Make certain that the horizontal axis                @ is within the viewing window.                'PPAR' 1 GETI IM 3 ROLLD GETI IM 3 ROLLD DROP2                \-> y0 y1                \<< y0 y1 *                    IF 0 >                    THEN                        IF y0 0 >                        THEN                            0 y1 YRNG                        ELSE                            y0 0 YRNG                        END                    END                \>>                DRAX                DRAW            END            RPAR TAIL LIST\-> DROP                          @ x n a b            IF 'choice==2' THEN SWAP END                    @ (RH sum?) Work from right to left            \-> x n a b            \<< 1 n 1 -                                     @ 1 n-1                b a - n / \->NUM                            @ 1 n-1 h                0 0                                         @ 1 n-1 h xL yL                IFERR                                       @ Flag illegal values                    a RCEQ x 3 PICK 2 \->LIST | \->NUM      @ 1 n-1 h xL yL xR yR                    DUP TYPE IF 1 == THEN DOERR END         @ A complex value is an error                THEN                    7 DROPN                    7 FREEZE                    "Integrand is complex or undefined at "                    x \->STR + " = " + a \->STR + MSGBOX                    KILL                END                CASE                                        @ Push the initial sum onto the stack                    'choice==1 OR                     choice==2' THEN DUP END                @ xR yR sum                    'choice==3' THEN DUP                                     IFERR                                         RCEQ x b 2 \->LIST | \->NUM                                         DUP TYPE IF 1 == THEN DOERR END                                     THEN                                         8 DROPN                                         7 FREEZE                                         "Integrand is complex or undefined at "                                         x \->STR + " = " + b \->STR + MSGBOX                                         KILL                                     END                                     + 2 /                                END                @   'choice==4' THEN  END                @   'choice==5' THEN  END                    "ERROR!: Unknown sum type!" MSGBOX 7 DROPN KILL @ Flag an illegal choice                END                \-> h xL yL xR yR sum                \<< START                        IF plot                        THEN                            xR 'xL' STO                            yR 'yL' STO                        END                        h 'xR' STO+                                        @ Update xR                        IFERR                            RCEQ x xR 2 \->LIST | \->NUM DUP 'yR' STO      @ Update yR                            DUP TYPE IF 1 == THEN DOERR END                @ A complex value is an error                        THEN                            DROP                            7 FREEZE                            "Integrand is complex or undefined at "                            x \->STR + " = " + xR \->STR + MSGBOX                            KILL                        END                        'sum' STO+                                         @ Update sum                        IF plot                        THEN                            CASE                                '(choice==1) OR (choice==2)'                                    THEN                                        xL 0 R\->C xR yL R\->C BOX                                    END                                'choice==3'                                    THEN                                        xL yL R\->C xL 0 R\->C OVER LINE                                        xR yR R\->C xR 0 R\->C OVER LINE LINE                                    END                            @   'choice==4' THEN  END                            @   'choice==5' THEN  END                            @   Error trap is unnecessary here, since earlier trap is sufficient.                            END                        END                    NEXT                    sum h ABS * DUP                    choices choice GET " Sum" + \->TAG      @ Push tagged result onto stack                    SWAP                    IF plot                                 @ Draw the last strip                    THEN                        xR 'xL' STO                        yR 'yL' STO                        b  'xR' STO                        IFERR                            RCEQ x xR 2 \->LIST | \->NUM                            DUP TYPE IF 1 == THEN DOERR END                        THEN                            3 DROPN                            7 FREEZE                            "Integrand is complex or undefined at "                            x \->STR + " = " + xR \->STR + MSGBOX                            KILL                        END                        'yR' STO                        CASE                            '(choice==1) OR (choice==2)'                                THEN                                    xL 0 R\->C xR yL R\->C BOX                                END                            'choice==3'                                THEN                                    xL yL R\->C xL 0 R\->C OVER LINE                                    xR yR R\->C xR 0 R\->C OVER LINE LINE                                END                        @   'choice==4' THEN  END                        @   'choice==5' THEN  END                        @   Error trap is unnecessary here, since earlier trap is sufficient.                        END                        2 FIX LABEL STD                        7 FREEZE                        2 WAIT                        "sum" \->TAG \->STR MSGBOX                    ELSE                        DROP                    END                \>>            \>>        \>>    \>>\>>

Click here to download an electronic copy. (To load this directly into your calculator, you will need hplink hardware and hplink or hpcomm software or an equivalent.)


09/05/96(jac)