Post Reply 
(42S) Recurring Sequence Matrix
07-11-2016, 05:04 AM
Post: #1
(42S) Recurring Sequence Matrix
HP 42S: Recurring Sequence Matrix

The program RECUR builds a table for the sequence f(n, u(n-1)). The table is stored in the matrix MAT. At the completion of the program, you will be to see the elements of MAT in matrix edit mode.

LBL 00 holds the sequence function.
R00 = u(n-1)

Specify as many entries as you like, up to 999.

To use the counter in the sequence function, use RCL 02, IP.

Other registers that are used are:
R01 = n
R02 = counter, in the form of 2.nnn

Code:
HP 42S Program RECUR
00 {“95+” Byte Prgm}  \\ varies depending on the sequence function
01 LBL “RECUR”
02 “U(1)=”
03 PROMPT
04 STO 00  \\ store the initial condition
05 “# TERMS:”
06 PROMPT
07 STO 01  \\ store n
08 2
09 DIM “MAT” \\ create the matrix MAT (n x 2)
10 1E-3
11 RCL* 01
12 2
13 + 
14 STO 02 \\ set up counter
15 INDEX “MAT” \\ index the matrix 
16 1
17 ENTER
18 STOIJ  \\ set index counters at I=1 (row), J=1 (col)
19 1
20 STOEL  \\  store 1 into MAT(1,1)
21 J+  \\  XEQ “J+”  
22 RCL 00
23 STOEL  \\ store U(1) into MAT(1,2)
24 J-  \\ XEQ “J-“, set column pointer back to 1
25 LBL 10  \\ main loop
26 I+ \\ XEQ “I+”, go to the next row
27 RCL 02
28 IP
29 STOEL
30 J+  \\ XEQ “J+”
31 RCL 00  \\ recall u(n-1)
32 XEQ 00 \\ calculate f(n, u(n-1))
33 STO 00 \\ store u(n) for the next loop
34 STOEL
35 J-  \\ XEQ “J-“
36 ISG 02  \\ increase counter
37 GTO 10
38 RCL “MAT” 
39 EDIT \\ put MAT in viewing/editing mode
40 RTN  \\ main program ends

41  LBL 00

NN RTN \\ end sequence function with RTN
NN+1 END

How to run RECUR:
1. If desired, edit the function by [shift] [XEQ] (GTO) 00, [shift] [R/S] (PRGM). Remember you start with u(n-1) in the X stack. End f(x) with RTN.
2. Press [XEQ] {RECUR}. You will be prompted for U(1) and the number of rows desired.

Test 1: u(n) = 2*u(n-1), u(1) = 1, 5 rows wanted

Code:
41 LBL 00
42 2
43 *
44 RTN
45 END

[XEQ] {RECUR} 1 [XEQ] 5 [XEQ]

MAT =
1 1
2 2
3 4
4 8
5 16

Test 2: u(n) = u(n-1)^2 – u(n-1)^3/6, u(1) = 1.5, 5 rows wanted

Code:
41 LBL 00
42 ENTER
43 X^2
44 X<>Y
45 3
46 Y^X
47 6
48 ÷
49 – 
50 RTN
51 END

MAT =
1 1.5000
2 1.6875
3 2.0468
4 2.7602
5 4.1138
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)