Showing posts with label geometric series. Show all posts
Showing posts with label geometric series. Show all posts

Saturday, August 7, 2021

TI-95 ProCalc: Arithmetic and Geometric Series, Arithmetic-Geometric Mean

TI-95 ProCalc: Arithmetic and Geometric Series, Arithmetic-Geometric Mean




Welcome to TI-95 ProCalc month!  I think this is the first time I am going to post programs for this classic keystroke calculator.  


To see my review of the TI-95 ProCalc in 2020, click here:

http://edspi31415.blogspot.com/2020/07/retro-review-ti-95-procalc.html

Note, all programs on this series will use the one-letter variables A-Z, which can also be registers 000 - 025. 


Arithmetic Term and Sum


Arithmetic Series:

a + (a + d) + (a + 2d) + ...


Nth Term:

TERM = B = a + (n -1) * d


Sum of N Terms:

SUM = S = n / 2 * (2 * a + (n - 1) * d) = n / 2 * (a + TERM)


Alpha strings are enclosed in singular quotes (' ').


TI-95 ProCalc Program File ARI

Size: 72 bytes


'A+(A+D)+...'  BRK CLR


'A?' BRK STO A


+ ( 'N?' BRK STO N 


- 1 ) * 'D?' BRK = STO B


+ RCL A = * RCL N / 2 = STO S


'TERM=' COL 16 MRG B BRK 


CLR 'SUM=' COL 16 MRG S HLT


Examples

 

A = -1, D = 6, N = 20

Results:  TERM = 113, SUM = 1,120


A = 4.5, D = 1.8, N = 35

Results:  TERM = 65.7, SUM = 1,228.5



Geometric Series and Sum


Geometric Series:

a + a*r + a*r^2 + a*r^3 + ...


Nth Term:

TERM = B = a * r^(n-1)


Sum of N Terms:

SUM = S = (a * (1 - r^n)) / (1 - r) = ( -r * TERM + a ) / (1 - r )


TI-95 ProCalc Program File GMS

Size: 80 bytes


'A+A*R+A*R^2+...' BRK CLR


'A?' BRK STO A* 


'R?' BRK STO R y^x 


( 'N?' BRK - 1 ) = STO B

 

* RCL R +/- + RCL A = 


/ ( 1 - RCL R ) = STO S


'TERM=' COL 16 MRG B BRK


CLR 'SUM=' COL 16 MRG S HLT


Examples


A = 1,000, R = 1.36, N = 32

Results: TERM = 13,794,506.22, SUM = 52,109,801.29 


A = 1,000, R = 0.95, N = 26

Results: TERM = 277.3895731, SUM = 14,729.59811


Arithmetic-Geometric Mean


Given positive real numbers A and G, the follow algorithm repeats until A and G converge:


A_n+1 = (A_n + G_n) / 2

G_n+1 = √(A_n * G_n)


When convergence is satisfied to a set of decimal places, both A_final and G_final are calculated for comparison purposes.


TI-95 ProCalc Program File AGM

Size: 104 bytes


CLR 'ARITH/GEOM MEAN' PAU


CLR 'A?' BRK STO A


CLR 'G?' BRK STO G


CLR '# PLACES?' BRK +/- INV LOG STO T 


LBL 01 RCL A STO B RCL G STO H


( RCL B + RCL H ) / 2 = STO A


( RCL B * RCL H ) SQR = STO G


( RCL A - RCL G ) ABS = IF> T GTL 01 


RCL G x~t RCL A HLT


Examples


A = 2.4, G = 3.6, # PLACES = 6 (6 places)

Results:  2.969616524, 2.969616523


A = 105, G = 207, # PLACES = 6 (6 places)

Results:  151.6836959, 151.6836959


Source for Arithmetic and Geometric Term and Sum:


Lindeburg, Michael R. P.E.  Engineering Fundamentals: Quick Reference Cards Third Edition  Professional Publications, Inc.  Belmont, CA 1988 ISBN 0-932276-88-1


Commas added to the results for readability.  


Eddie


All original content copyright, © 2011-2021.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Sunday, January 3, 2021

Swiss Micros DM42 and HP71B: Present Value of a Growing Annuity

Swiss Micros DM42 and HP71B: Present Value of a Growing Annuity


Introduction


Today we are going to calculate the present value of a growing annuity.  Unlike most annuities where the payment is constant, in a growing annuity, the payment increases each period.  For this particular blog, we are working with annuities that payments increase by a growth percent (g%) each period.  The annuity has an different interest rate (r%) in which payments are discounted.  


Since the payments are not constant, the time value of money (TVM) keys on a financial calculator are not going to be used.  If your calculator has the the net present value (NPV) function, this can assist you in these calculations.

I am going to use a different approach.


Derivation





Variables:


P = base payment (the first payment)

g = growth rate per period 

r = interest rate per period

n = number of periods 

PV = present value


Ordinary Growing Annuity


In an ordinary growing annuity, the first payment will be received after one period (typically a year or a month) has passed.  Discounting all the payments to calculate present value:


PV 

=  P/(1+r) + P * (1+g)/(1+r)^2 + P * (1+g)^2/(1+r)^3 + ... + P * (1+g)^(n-1)/(1+r)^n

=  P/(1+r) * [ 1 + (1+g)/(1+r) + (1+g)^2/(1+r)^2 + ... + (1+g)^(n-1)/(1+r)^(n-1)


Let w = (1+g)/(1+r), then:


PV

= P/(1+r) * [ 1 + w + w^2 + ... + w^(n-1) ]


The result is a geometric series.  In a general geometric series:


a + a*r + a*r^2 + ... + a*r^(n-1) = Σ(a*r^k, k=0 to n-1) = a * (1 - r^n)/(1 - r)


Then:


PV

= P/(1+r) * [ 1 + w + w^2 + ... + w^(n-1) ]

= P/(1+r) * Σ(w^k, k=0 to n-1) 

= P/(1+r) * (1 - w^n)/(1 - w)


Alternatively, change w back to (1+g)/(1+r):


PV

= P/(1+r) * (1 - (1+g)^n/(1+r)^n) / (1 - (1+g)/(1+r))

= [ P/(1+r) * (1 - (1+g)^n/(1+r)^n) ] / [ 1 - (1+g)/(1+r) ]

= [ P/(1+r) * P/(1+r) * (1+g)^n/(1+r)^n ] / [ 1 - (1+g)/(1+r) ]


The article from finaceformulas.net (see source) suggests multiplying by (1+r) / (1+r):


= [ P/(1+r) - P/(1+r) * (1+g)^n/(1+r)^n ] / [ 1 - (1+g)/(1+r) ] * (1 + r) / (1 + r)

= [ P - P * (1+g)^n/(1+r)^n ] / [ 1 + r - (1 + g) ]

= [ P - P * (1+g)^n/(1+r)^n ] / [ r - g ]

= P / (r - g) * (1 - (1+g)^n/(1+r)^n )


Growing Annuity Due


On an annuity due, the first payment takes place immediately.  The present value is calculated as:


PV 

=  P +  P * (1+ g)/(1+r) + P * (1+g)^2/(1+r)^2 + P * (1+g)^3/(1+r)^3 + ... + P * (1+g)^n/(1+r)^n

=  P * [ 1 + (1+ g)/(1+r) + (1+g)^2/(1+r)^2 + (1+g)^3/(1+r)^3 + ... + (1+g)^n/(1+r)^n ]


Let w = (1+g)/(1+r), then:


PV 

= P * [1 + w + w^2 + w^3 + ... + w^n ]


We have another geometric progression:


PV 

= P  * (1 - w^(n+1))/(1 - w)


Summary:


Present Value of a Growing Annuity - Ordinary


PV = P/(1+r) * (1 - w^n)/(1 - w)


Present Value of a Growing Annuity - Due


PV = P  * (1 - w^(n+1))/(1 - w)


HP 42S/DM42 Program:  PVGROW


Both PVGROW and PVGDUE use only one register, R01.


00  {79-Byte Prgm}

01  LBL "PVGROW"

02  "BASE PMT?"

03  PROMPT

04  "INTEREST?"

05  PROMPT

06  1

07  X<>Y

08  %

09  +

10  STO 01

11  ÷

12  1

13  "GROWTH?"

14  PROMPT

15  %

16  +

17  RCL÷ 01

18  STO 01

19  "N?"

20  PROMPT

21  Y↑X

22  1

23  X<>Y

24  -

25  1

26  RCL- 01

27  ÷

28  ×

29  "PV="

30  ARCL ST X

31  AVIEW

32  END


HP 42S/DM42 Program:  PVGDUE


00  {79-Byte Prgm}

01  LBL "PVGDUE"

02  "BASE PMT?"

03  PROMPT

04  "INTEREST?"

05  PROMPT

06  1

07  X<>Y

08  %

09  +

10  1

11  "GROWTH?"

12  PROMPT

13  %

14  +

15  ÷

16  1/X

17  STO 01

18  "N?"

19  PROMPT

20  1

21  +

22  Y↑X

23  1

24  X<>Y

25  -

26  1

27  RCL- 01

28  ÷

29  ×

30  "PV="

31  ARCL ST X

32  AVIEW

33  END


HP 71B Program: PVGROW


Note:  This is for both ordinary and growing annuities due.


100  DESTROY P,G,R,W,A,C

105  INPUT "PAYMENT? "; P

110  INPUT "INTEREST? "; R

115  R=.01*R

120  INPUT "GROWTH? "; G

125  G=.01*G

130  W=(1+G)/(1+R)

135  INPUT "N? "; N

140  INPUT "DUE?(Y=1,N=0) ";C

145  IF C=1 THEN 200

150  IF C=0 THEN 300 ELSE 140 


200  A=P*(1-W^(N+1))/(1-W) @ ! DUE

205  GOTO 400


300  A=P*(1-W^N)/((1+R)*(1-W)) @ ! ORD

305 GOTO 400


400 PRINT "PV ="; A

  

Examples:


Base Payment:  P = 20.00

Interest Rate:  r = 4%

Growth Rate:  g = 5%

n = 5


Ordinary Growing Annuity


Result:  PV = 98.02


Timeline of Payments:

Period 0:  0.00

Period 1:  20.00

Period 2:  21.00

Period 3:  22.05

Period 4:  23.15

Period 5:  24.31


Growing Annuity Due


Result:  PV = 122.92


Period 0:  20.00

Period 1:  21.00

Period 2:  22.05

Period 3:  23.15

Period 4:  24.31

Period 5:  25.53


Source:


"Present Value of a Growing Annuity" financeformulas.net  https://financeformulas.net/Present_Value_of_Growing_Annuity.html   Retrieved December 13, 2020.  


Eddie


All original content copyright, © 2011-2021.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Sunday, December 9, 2018

Fun with the Infinite Series 1 + x + x^2 + x^3 + x^4 + x^5 + ...

Fun with the Infinite Series 1 + x + x^2 + x^3 + x^4 + x^5 + ...


The Series and Its Derivatives

Let F be the infinite series:

F = 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + ... = ∑ x^k from k = 0 to ∞.

Working with derivatives:

----

First Derivative of F:  (F' = dF/dx)

F' = 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 + 6*x^5 + 7*x^6 + ... 
= ∑ (k+1)*x^k from k = 0 to ∞

----

Second Derivative of F:  (F'' = d^2F/dx^2)

F'' = 2 + 6*x + 12*x^2 + 20*x^3 + 30*x^4 + 42*x^5 + 56*x^6 + ....

Factor out a 2:
= 2 * (1 + 3*x + 6*x^2 + 10*x^3 + 15*x^4 + 21*x^5 + 28*x^6 + .... )

Note the sequence 1, 3, 6, 10, 15, 21, 28...  These are triangle numbers, denoted as T_n.  

T_1 = 1
T_2 = 1 + 2 = 3
T_3 = 1 + 2 + 3 = 6
T_4 = 1 + 2 + 3 + 4 = 10 
and so on.

Using summation notation,  T_n = ∑ k from k = 1 to n

Going back to the series:

F'' = 2 + 6*x + 12*x^2 + 20*x^3 + 30*x^4 + 42*x^5 + 56*x^6 + ....
= 2 * (1 + 3*x + 6*x^2 + 10*x^3 + 15*x^4 + 21*x^5 + 28*x^6 + .... )
= 2 * (∑ x^k * T_k+1 from k = 0 to ∞)

In nested summation notation:

= 2 * (∑ x^k * (∑ m from m = 1 to k+1) from k = 0 to ∞)


Addition with F, F', and F"


F + F' = 2 + 3*x + 4*x^2 + 5*x^3 + 6*x^4 + 7*x^5 + 8*x^6 + ...
= ∑ ((k + 2) * x^k from k = 0 to ∞)

----

F + F' + F'' = 4 + 9*x + 16*x^2 + 25*x^3 + 36*x^4 + 49*x^5 + 64*x^6 + ...
= ∑ ((k + 2)^2 * x^k from k = 0 to ∞)

----

F' + F" = 3 + 8*x + 15*x^2 + 24*x^3 + 35*x^4 + 48*x^5 + 63*x^6 + ...

Note the sequence 3, 8, 15, 24, 35, 48, 63... where
3 = 4 - 1 = 2^2 -1
8 = 9 - 1 = 3^2 - 1
15 = 16 - 1 = 4^2 - 1
24 = 25 - 1 = 5^2 - 1
35 = 36 - 1 = 6^2 - 1
48 = 49 - 1 = 7^2 - 1
63 = 64 - 1 = 8^2 - 1
and so on...

This can be summarized as ∑( (k + 2)^2 - 1 from k = 0 to ∞)

Hence:
F' + F" = 3 + 8*x + 15*x^2 + 24*x^3 + 35*x^4 + 48*x^5 + 63*x^6 + ...
= ∑  ((k + 2)^2 - 1) * x^k from k = 0 to ∞)

Multiplying F and F' by x and x^2 

F = 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + ... = ∑ x^k from k = 0 to ∞.
x * F = x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + ... = ∑ x^(k+1) from k = 0 to ∞.
x^2 * F =  x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + ... = ∑ x^(k+2) from k = 0 to ∞.

-----

F + x * F = 1 + 2*x + 2*x^2 + 2*x^3 + 2*x^4 + 2*x^5 + 2*x^6 + ...
= 2 - 1 + 2*x + 2*x^2 + 2*x^3 + 2*x^4 + 2*x^5 + 2*x^6 + ...
= 2 + 2*x + 2*x^2 + 2*x^3 + 2*x^4 + 2*x^5 + 2*x^6 + ... - 1
= 2 * F - 1

This is one way to dervie the formula for the Infinite Geometric Series (for |x| < 1), to solve for F:

F + x * F  = 2 * F - 1
F + x * F - 2 * F = -1
F * (1 + x - 2) = -1
F * (x - 1) = -1
F = -1 / (x - 1)
F = 1 / (1 - x)   (keep this mind, this is true only when |x| < 1)

----

F - x * F = (1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + ... ) - (x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + ... )
= F * (1 - x)

For |x| < 1,

F * (1 - x) = 1 / (1 - x) * (1 - x) = 1

In general:
F - x * F = (1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + ... ) - (x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + ... )
= 1 + (x - x) + (x^2 - x^2) + (x^3 - x^3) + (x^4 - x^4) + (x^5 - x^5) + (x^6 - x^6) + ...
= 1

F - x * F = 1

----

F' = 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 + 6*x^5 + 7*x^6 + ... 
= ∑ ((k + 1) * x^k from k = 0 to ∞)

x * F' = x + 2*x^2 + 3*x^3 + 4*x^4 + 5*x^5 + 6*x^6 + 7*x^7 + ... 
= ∑ ((k + 1) * x^(k + 1) from k = 0 to ∞)


x^2 * F' = x^2 + 2*x^3+ 3*x^4 + 4*x^5 + 5*x^6 + 6*x^7 + 7*x^8 + ... 
= ∑ ((k + 1) * x^(k + 1) from k = 0 to ∞)

----

F' + x * F' = 1 + 3*x + 5*x^2 + 7*x^3 + 9*x^4  + 11*x^5 + 13*x^6 + ...

The sequence of 1, 3, 5, 7, 9, 11, 13, ... is the sequence of odd numbers which can be summarized as:

∑(2 * k + 1 from k = 0 to ∞)

Then:

F' + x * F'  =  F' * (1 + x) = ∑( (2*k + 1) * x^k from k = 0 to ∞)

----

F' + x * F' + x^2 * F' = 1 + 3*x + 6*x^2 + 9*x^3 + 12*x^4 + 15*x^5 + 18*x^6 + ...
= 1 + ( 3*x + 6*x^2 + 9*x^3 + 12*x^4 + 15*x^5 + 18*x^6 + ... )
= 1 + ∑(3 * k * x^k from k = 0 to ∞)

Eddie

All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

Thursday, May 10, 2012

Calculus Revisited #18: Series

Welcome to Part 18 of our wonderful 21 part of our Calculus Revisited Series. I hope you are enjoying this series. An announcement: Part 21 will be a "catch all" section - covering some of the topics we don't get to in detail in this series.

The next three blog entries will be about series. Today, the basics.

Series:

A series is a sum of terms in a sequence. The series can be finite or infinite. An infinite series is convergent (has a value) if the following is true:


∑ a_n = S
n=i

and S < ∞

Here are some famous series:

Arithmetic Series:

a + (a + d) + (a + 2d) + (a + 3d) + ...

Sum for a finite arithmetic series:

n-1
∑ a + k * d
k=0

= a * n + (d * n * (n -1))/2

Geometric Series:

a + a * r + a * r^2 + a * r^3 + ...

Sum for an infinite geometric series, provided that |r| < 1:


∑ a * r^k = a / (1 - r)
k = 0

Harmonic Series:


∑ 1/n
n=1

= 1 + 1/2 + 1/3 + 1/4 + 1/5 + ....

There is no closed formula for a finite harmonic series. In addition the infinite harmonic series diverges (has no sum).

Series Properties:

∑ c * a(n) = c * ∑ a(n) (c is a constant)

∑ a(n) + b(n) = ∑ a(n) + ∑ b(n)

n
∑ k = n * (n + 1)/2
k=1

n
∑ k^2 = n * (n + 1) * (2n + 1)/6
k = 1

n
∑ k^3 = n^2 *(n + 1)^2 / 4
k = 1


Subtracting from a whole:
If t > 1:

k
∑ a(n) =
n = t

∑( a(n) for n = 1 to k) - ∑( a(n) for n = 1 to t - 1)


Problems

1. Calculate

6
∑ 50 - 2k
k = 0

This is an arithmetic series with n = 6 + 1 = 7, a = 50, and d = -2.

Then the sum is:
(50)(7) + (-2 * 7 * 6)/2 = 308


2. Show why the (infinite) harmonic series is divergent.

Here is one way:

Let S be the sum of the harmonic series, that is:

S = 1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 + 1/7 + 1/8 + ...

Note that:
1 + 1/2 > 2/2
1/3 + 1/4 > 2/4
1/5 + 1/6 > 2/6
1/7 + 1/8 > 2/8
and so on...

Then we have 2/2 + 2/4 + 2/6 + 2/8 + ....

Which simplifies to 1 + 1/2 + 1/3 + 1/4 + .... = S

Which implies S > S, which is impossible.

The harmonic series is divergent.

3. Find the sum:


∑ .5^n + .3^n
n=0

We can first break the sum up:

∑(.5^n for n=0 to ∞) + ∑(.3^n for n=0 to ∞)

Both terms are geometric series. r = .5 for the first term and r = .3 for the second term.

Then:

∑(.5^n for n=0 to ∞) + ∑(.3^n for n=0 to ∞)
= 1 / (1 - .5) + 1 / (1 - .3)
= 1 / .5 - 1 / .7
= 24/7 ≈ 3.42857

4. Find the sum:


∑ 2 / (5^n)
n = 1

This looks like a geometric series with r = 1/5. If we can put the sum into it's proper form, perhaps by adding and subtracting 2 / 5^0:

∑( 2 / (5^n) for n = 1 to ∞)
= ∑ ( 2 / (5^n) for n = 0 to ∞) - 2 / 5^0
= ∑ ( 2 / (5^n) for n = 0 to ∞) - 2
= 2 / ( 1 - 1/5) - 2
= 2 / (4/5) - 2
= 5/2 - 2 = 1/2

5. Find the sum:

20
∑ k^2
k=10

Again, looks like a k^2 series, but use the subtraction from the whole technique and:

∑( k^2 for k = 10 to 20)
= ∑(k^2 for k = 1 to 20) - ∑(k^2 for k = 1 to 10 - 1)
= (20)(20 + 1)(2 * 20 + 1)/6 - (9)(9 + 1)(2 * 9 + 1)/6
= 17220 / 6 + 1710 / 6
= 15510 / 6 = 2585

Thank you once again for joining us. Next time we will work some series convergence tests.

Eddie

This blog is property of Edward Shore. © 2012

RPN HP 12C: Fibonacci and Lucas Sequences

  RPN HP 12C: Fibonacci and Lucas Sequences Golden Ratio, Formulas, and Sequences Let φ be the Golden Ratio: φ = (1 + √5) ÷ 2...