Post Reply 
(11C) n-th term of a Geometric Sequence
05-21-2018, 09:31 AM (This post was last modified: 05-22-2018 11:52 AM by Gamo.)
Post: #1
(11C) n-th term of a Geometric Sequence
Nth term of a Geometric Sequence giving
Initial Value (a)
Common Ratio (r)
Term (n)

Formula: a sub n = ar^n-1 for every integer n ≥ 1

More information about Geometric Progression:
https://en.wikipedia.org/wiki/Geometric_progression

Example:
a=2
r=3.14
n=14

Procedure:
Set User Mode
2 A > 2 // Input initial value
3.14 B > 3.14 // Input common ratio
14 C > 14 // Input term
D > 5769197.69 // answer on the 14th term

What is the sequence number on the 1st and 2nd term on the above example?

(1st Term) 1 C > D > 2
(2nd Term) 2 C > D > 6.28

The sequence are 2, 6.28, 19.72, 61.92,.......

Program:
Code:

LBL A  // Initial Value
STO 1
RTN
LBL B  // Common Ratio
STO 2
RTN
LBL C  // n-term
STO 3
RTN
LBL D
RCL 2
X>0?   // Test Common Ratio for Positive or Negative value 
GTO 1
RCL 3
RCL 3
2
÷
FRAC
2
x
X=0?    // Test n-th term for Even or Odd number
GTO 3
GSB 2    // Odd integer of n-th term
RCL 1
x
RTN
LBL 1    // Common Ratio is Greater than Zero
RCL 2
RCL 3
1
-
Y^X
RCL 1
x
RTN
LBL 2    // identical routine for common ratio value Less than Zero
RCL 2
RCL 3
1
-
X<>Y
CHS
X<>Y
Y^X
RTN
LBL 3    // Even integer of n-th term
GSB 2
CHS
RCL 1
x
RTN

Remark:
The common ratio of a geometric sequence may be negative, resulting in an alternating sequence, with numbers switching from positive to negative and back. For instance

1, −3, 9, −27, 81, −243, ...
is a geometric sequence with common ratio −3.

Input 1 A, -3 B, and your choice of term [C] then [D] for answer.

------------------------------------------------------------------------------
This update version can be use for the following:

LBL A // To display a geometric progression
LBL B // To find from the n-th term
LBL C // To find the sum of the giving n-th term

Procedure:
For geometric sequence: (a) ENTER (r) > f [A] > continue [R/S]
For n-th term: (a) ENTER (r) ENTER (n) > f [B]
For the Sum of given n-th term: (a) ENTER (r) ENTER (n) > f [C]

Example:
a=1
r= -3
n= selected term

Sequence: 1, -3, 9, -27, 81, -243,......

Geometric Sequence: 1 ENTER -3 f [A] > 1 > [R/S] > -3 > [R/S] > 9
4th term: 1 ENTER -3 ENTER 4 f [B] > -27
Sum to 4th term: 1 ENTER -3 ENTER 4 f [C] > -20

Program:
Code:

LBL A  // Geometric Sequence 
ENTER
ENTER
R^
LBL 1
R/S
x
GTO 1
LBL B    // n-th term
Rv
Rv
STO 3
Rv
Rv
1
-
GSB 2
RCL 3
x
RTN
LBL C    // Sum to the n-th term
Rv
STO 4
Rv
STO 3
Rv
Rv
GSB 2
1
-
RCL 3
x
RCL 4
1
-
÷
RTN
LBL 2
STO 1
X<>Y
STO 2
0
X<>Y
X>Y
GTO 3
CHS
STO 2
RCL 1
2
÷
FRAC
0
X=Y
GTO 3
RCL 2
RCL 1
Y^X
CHS
RTN
LBL 3
RCL 2
RCL 1
Y^X
RTN

Gamo
Find all posts by this user
Quote this message in a reply
05-21-2018, 12:47 PM (This post was last modified: 05-21-2018 01:31 PM by Dieter.)
Post: #2
RE: (11C) n-th term of a Geometric Sequence
(05-21-2018 09:31 AM)Gamo Wrote:  Formula: a sub n = ar^n-1 for every integer n ≥ 1

an = a1 · rn–1

(05-21-2018 09:31 AM)Gamo Wrote:  
Code:
LBL D
RCL 2
X>0?   // Test Common Ratio for Positive or Negative value 
GTO 1
...
X=0?    // Test n-th term for Even or Odd number
GTO 3
GSB 2    // Odd integer of n-th term
RCL 1
x
RTN
LBL 1    // Common Ratio is Greater than Zero
...
LBL 2    // identical routine for common ratio value Less than Zero
...
LBL 3    // Even integer of n-th term
GSB 2
CHS
RCL 1
x
RTN

Gamo, all these tests and subroutines are not required. You do not have to check whether r is negative or not, and if it is, also check if n is odd or even. All HP calculators I know can calculate integer powers of negative bases directly. So (–3,14)5 directly yields –305,24... without any problem.

This means the more than 40 steps routine at LBL D can be replaced with this:

Code:
LBL D
RCL 2
RCL 3
1
-
Y^X
RCL 1
x
RTN

That's it.

If you really want to check for odd or even n and whether r is negative or not, you could do it much shorter. Simply calculate the power with |r| and change the sign if r<0 and n is even. For instance this way:

Code:
LBL D
CF 0
RCL 2
X>0?
GTO 1  // keep flag 0 clear for r>0
RCL 3
2
/
FRAC   // for r<0 check if n is odd or even
X=0?   // if n is even
SF 0   // set flag 0
LBL 1
RCL 2
ABS    // calculate |r|^(n-1)
RCL 3
1
-
Y^X
RCL 1
x
F? 0
CHS    // change sign if r<0 and n even
CF 0
RTN

But again: all this is not required.

You know I'm a big fan of using the stack instead of registers, so here's how I would do it:

Code:
LBL A
ENTER
1
-
X<>Y
ENTER
R↓
X<>Y
Y^X
x
RTN

The ENTER in the second line usually is not required, but this way the program will also run on an HP25. ;-)

Usage:
a1 [ENTER] r [ENTER] n
[A] => an
[x] => an+1
[x] => an+2
...

Example:
1 [ENTER] –3 [ENTER] 1
[A]   1
[x] –3
[x]   9
[x] –27
[x]   81
[x] –243
...

Dieter
Find all posts by this user
Quote this message in a reply
05-21-2018, 03:42 PM
Post: #3
RE: (11C) n-th term of a Geometric Sequence
Dieter Thank You

I like the shorter solution for even or odd routine.

Your version of the step through a geometric progression is good but my manual version is easier.

Steps:
(r) ENTER ENTER ENTER
(a)
x (multiply) keep repeat this x as desire

Example:
1, −3, 9, −27, 81, −243, ...

-3 ENTER ENTER ENTER
1
X (repeat multiplication)

Gamo
Find all posts by this user
Quote this message in a reply
05-21-2018, 04:06 PM (This post was last modified: 05-21-2018 04:08 PM by Dieter.)
Post: #4
RE: (11C) n-th term of a Geometric Sequence
(05-21-2018 03:42 PM)Gamo Wrote:  I like the shorter solution for even or odd routine.

Maybe it has not become clear yet: You do not need this odd/even thing at all!
The 11 step program does it all.

(05-21-2018 03:42 PM)Gamo Wrote:  Your version of the step through a geometric progression is good but my manual version is easier.

Steps:
(r) ENTER ENTER ENTER
(a)
x (multiply) keep repeat this x as desire

Sure... if you start at the beginning of the sequence, i.e. n=1. With the program you can start at, say, n=20 and continue from there.

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 




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