Summation Program

Description

By Eddie Shore, November 2011 (Eddie's Math and Calculator Blog)

This program computes the sum:

R0 = ∑( X = R1, R2, f(R1))

where:
R0 = the sum
R1 = starting value, which gets updated at each step. R1 is also used as the variable for f(X)
R2 = finishing value

The program uses three labels:

Label A: The main routine. Press f A to run the routine.
Label 1: A subroutine of Label A. This is the loop.
Label 0: Where the function f(X) is stored. Assume that R1 is loaded on the X register when programming the function.

The program presented here will allow the user to enter starting and ending values beyond 999. You can shorten the program by the use of ISG, however, the ending value would be restricted to 999.

Instructions:
  1. Enter the main program (Labels A and 1).
  2. Enter the function f(R1) (Label 0).
  3. In run mode, enter the starting value and press ENTER
  4. Enter the ending value and press f A
  5. The sum is calculated and displayed.
Remember: Always finish the function with the RTN command (g RTN).

Example 1:

Find the sum ∑(X = 1, 50, X). In other words, what is the sum of the integers from 1 to 50?

Program listing for f(R1):
     Key Code     Key
001  42  21   0   LBL 0
002      43  32   RTN
Surprised? Remember we already have a copy of R1 in the main program when the instruction GSB 0 is encountered.

1 ENTER 50 f A
Result: 1275

Example 2:

Find the sum ∑(X = 1, 150, 1/(X2 + X)).

1/(X2 + X) can be rewritten as: (X2 + X)-1 = ((X + 1) X)-1. We will use the last form for our function.

A Way to Clear Label 0
Clear Label 0 is necessary. In Run mode, press GTO 0. Then press g P/R to enter program mode. Press SST until the key codes "43 32" is encountered. Press the backspace button the number of times you pressed SST. You should see the key code "42, 21, 0". You are ready to enter the new function.

Program Listing for f(R1):
     Key Code    Key
001  42  21  0   LBL 0
002         36   ENTER
003          1   1
004         40   +
005         20   ×
006         15   1/x
007     43  32   RTN

1 ENTER 150 f A
Result: ≈ 0.9934

Program Resources

Labels

Name Description
 A Summation
 0 User function
 1 Loop starts here

Storage Registers

Name Description
 0 total
 1 starting value
 2 ending value

Program

Line Display Key Sequence
000
001 42,21,11 f LBL A
002 0 0
003 44 0 STO 0
004 33 R⬇
005 44 2 STO 2
006 33 R⬇
007 44 1 STO 1
008 42,21, 1 f LBL 1
009 45 1 RCL 1
010 32 0 GSB 0
011 44,40, 0 STO + 0
012 1 1
013 44,40, 1 STO + 1
014 45 2 RCL 2
015 45 1 RCL 1
016 43 10 g x≤y
017 22 1 GTO 1
018 45 0 RCL 0
019 43 32 g RTN
020 42,21, 0 f LBL 0
021 43 32 g RTN