Showing posts with label recursion formula. Show all posts
Showing posts with label recursion formula. Show all posts

Monday, July 29, 2019

TI Nspire CX and Casio Micropython: Recursion Polynomials

TI Nspire CX and Casio Micropython:  Recursion Polynomials

Introduction

This blog entry deals with how to calculate functions defined as a recursion polynomial.  An example:

f_n(x) = 2 * f_n-1(x) + 1    where f_0(x) = x^2

We'll cover the TI Nspire CX (which is programmed in Basic) and the Casio fx-CG50's Micropython Module.

TI Nspire CX

The programs for the TI Nspire are in Basic (or some flavor of it), so it can easily be adapted for many programming and graphing calculators.  A possible template could be:

Input "X: ", x
Input "N: ", n
Local f, g, h, i 
//  f represents the function f_n
// g represents f_n-1
// h represents f_n-2
If n = 0: Then Return f_0(x):  Stop: IfEnd
If n = 1: Then Return f_1(x):  Stop: IfEnd
Else // if n > 1
For i =2 to n do
f := f_(x,g,h,i)   // i is used in placed for n
h:= g   // move values for the next loop
g:= f
Next
Return f  // final result

This is just one example on how to tackle this. 

Example 1: 
f_n = f_n-1 * (x + 1) - f_n-2
f_0 = 1
f_1 = x

Define recur1(n,x)=
Prgm
:Local f,g,h,i
:If n=0 Then
:  Disp 1
:ElseIf n=1 Then
:   Disp x
:ElseIf n>1 Then
:   h:=1
:   g:=x
:   For i,2,n
:     f:=g*(x+1)-h
:     h:=g
:     g:=f
:   EndFor
:   Disp f
:EndIf
:EndPrgm

Example 2:  Hermite Polynomial
H_n = 2 * x * H_n-1 - (2 * n - 2) * H_n-2
H_0 = 1
H_1 = 2 * x

Define numhermite(n,x)=
Prgm
:© numerical hermite polynomial
:Local f,g,h,i
:If n=0 Then
:  Disp 1
:ElseIf n=1 Then
:  Disp 2*x
:ElseIf n>1 Then
:  h:=1
:  g:=2*x
:  For i,2,n
:    f:=2*x*g-(2*i-2)*h
:    h:=g
:    g:=f
:  EndFor
:  Disp f
:EndIf
:EndPrgm

Example 3:  Parabolic Cylinder Function (aka Weber Function)
D_v+2 = x * D_v+1 - v * D_v
D_0 = e^(-x^2/4)
D_1 = x * e^(-x^/4)

Define parabcylin(v,x)=
Prgm
:© parabolic cylinder polynomial
:Local f,g,h,i
:If v=0 Then
:  Disp e^(((−x^(2))/(4)))
:ElseIf v=1 Then
:  Disp x*e^(((−x^(2))/(4)))
:ElseIf v>1 Then
:  h:=e^(((−x^(2))/(4)))
:  g:=x*e^(((−x^(2))/(4)))
:  For i,2,v
:    f:=x*g-(i-1)*h
:    h:=g
:    g:=f
:  EndFor
:  Disp f
:EndIf
:EndPrgm

Casio fx-CG 50 Micropython

Here is an approach using Python:

import math
N = float(input("N = "))
X = float(input("X = "))
if N==0:
  print(f_0)
elif N==1:
  print(f_1)
elif N>1:
  H = f_0
  G = f_1
  for i in range (2,N+1):
     F = f_n
     H = G
     G = F
 print(F)

Example 1: 
f_n = f_n-1 * (x + 1) - f_n-2
f_0 = 1
f_1 = x

recursio.py:
import math
N=float(input("N = "))
X=float(input("X = "))
if N==0:
  print(1)
elif N==1:
  print(X)  
else:
  H=1
  G=X
  for i in range(2,N+1):
    F=G*(X+1)-H
    H=G
    G=F
  print(F)
   
Example 2:  Hermite Polynomial
H_n = 2 * x * H_n-1 - (2 * n - 2) * H_n-2
H_0 = 1
H_1 = 2 * x

hermite.py:
import math
N=float(input("N = "))
X=float(input("X = "))
if N==0:
  print(1)
elif N==1:
  print(2*X)
else:
  H=1
  G=2*X
  for i in range(2,N+1):
    F=2*X*G-(2*i-2)*H
    H=G
    G=F
  print(F) 


Example 3:  Parabolic Cylinder Function (aka Weber Function)
D_v+2 = x * D_v+1 - v * D_v
D_0 = e^(-x^2/4)
D_1 = x * e^(-x^/4)

import math
N=float(input("N = "))
X=float(input("X = "))
if N==0:
  print(math.exp(-X**2/4))
elif N==1:
  print(X*math.exp(-X**2/4))
else:
  H=math.exp(-X**2/4)
  G=X*math.exp(-X**2/4)
  for i in range(2,N+1):
    F=X*G-(i-1)*H
    H=G
    G=F
  print(F) 
 

Numeric Examples to Try:

Example 1:
n = 2, x = 0.5,  result: -0.25
n = 3, x = -1.7, result: 1.567

Example 2:
n = 2, x = 2.2, result:  17.36
n = 4, x = -0.8, result: -12.1664

Example 3:
n = 0, x = 6.7, result: 1.3369921208E-5
n = 2, x = 0.3, result: 5.86807637482E-4

Happy Programming!

Source:

Keith Oldham, Jan Myland, Jerome Spainer.  An Atlas of Functions.  2nd Edition Springer:  New York.  2009  ISBN 978-0-387-48806-6

Eddie

All original content copyright, © 2011-2019.  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.

Saturday, February 16, 2013

a_(n+1) = a_n + n + C (from Stories Cafè in Echo Park in Los Angeles)

Good afternoon all! This is a Saturday Afternoon/Night blog post. On the menu: much needed delicious food from Stories Cafè in Los Angeles and some work with recurrence relations.

But first, an announcement! I am working on a short series of programming tutorials of the Hewlett Packard HP 39gii Calculator. Think of it as a short boot camp to get HP 39gii owners up and running.

An emulator for the HP 39gii can be found here: http://www.hp.com/sbso/product/calculators-emulators/graphic-calculator-emulators.html. The emulators are for Widows and probably Mac - not sure if they run on other operating systems. As of today, I am not aware if there are any iOS and/or Android apps for this. I aim to post this series in March 2013.

Now on to the math...

a_(n+1) = a_n + n + C

The goal is to find a general formula for

(I) a_(n+1) = a_n + n + C with the initial condition a_0 = A_0.

The type of recursion formula presented is polynomial recurring relation. A general polynomial recursion formula takes the form a_(n+1) = a_n + p(n).

The general formula for a_(n+1) = a_n + n + C takes the form:

(II) a_n = c_2 * n^2 + c_1 * n + c_0

Mainly, with recursion formula of polynomial type will require a formula of order n+1. There are n+2 constants to solve for.

Working with equation (II) above, we will need to solve for c_0, c_1, and c_2. It would be very difficult to work with only one equation. Luckily, we can turn this problem in to a system of three linear equations.

Starting with the initial condition a_0 = A_1, we can use the recursion formula for n=1 and n=2 to find a_1 and a_2. Then we get the system:

(III)
a_0 = c_0 (where n=0)
a_1 = c_0 + c_1 + c_2 (where n=1)
a_2 = c_0 + 2 * c_1 + 4 * c_2 (where n=2)

Putting (III) in matrix form we get:

(IV)
[ [1, 0, 0], [1, 1, 1], [1, 2, 4] ] * [ [c_0], [c_1], [c_2] ] = [ [a_0], [a_1], [a_2] ]

For the Hewlett Packard HP 50g calculator owners (others may have this function/program), you can get the matrix on the left hand side of equation (IV) by using the VANDERMONDE matrix function on the vector [0, 1, 2]. This function comes in handy for these types of problems.

Continuing with the ever handy HP 50g, solving for c_0, c_1, and c_2:

(V)
[ [c_0],[c_1],[c_2] ] = [ [1, 0, 0],[-3/2, 1, -1/2],[1/2, -1, 1/2] ] * [ [a_0], [a_1], [a_2] ]

And we finish with:
(VI)
c_0 = a_0
c_1 = -3/2 * a_0 + 2 * a_1 - 1/2 * a_2
c_2 = 1/2 * a_0 - a_1 + 1/2 * a_2


So in summary:
The general formula for the recursion formula

a_(n+1) = a_n + n + C is:

c_0 = a_0
c_1 = -3/2 * a_0 + 2 * a_1 - 1/2 * a_2
c_2 = 1/2 * a_0 - a_1 + 1/2 * a_2



A numerical example:

a_(n+1) = a_n + n - 2 with a_0=3

Prepare by finding a_0, a_1, and a_2:

a_0 = 3 (given)
a_1 = 3 + 1 - 2 = 2 (use n=1)
a_2 = 2 + 2 - 2 = 2 (use n=2)

Then:
c_0 = 3
c_1 = -3/2 * 2 + 2 * 2 - 1/2 * 2 = -3/2
c_2 = 1/2 * 2 - 2 + 1/2 * 2 = 1/2

Our general formula is:
a_n = 1/2 * n^2 - 3/2 * n + 3

Let's test it out.

With n=1:
a_1 = 1/2 - 3/2 + 3 = 2 (checks out)

With n=3
a_3 = 1/2 * 3^2 - 3/2 * 3 + 3 = 3

Observe from the recursion formula a_3 = 2 + 3 - 2 = 3. (Checks out)

With n=4
a_4 = 1/2 * 4^2 - 3/2 * 4 + 3 = 5


Warning: The above technique only works when the coefficient of a_n is 1. (See (I).)

I tried this technique with a_(n+1) = -3*a_n + 7*n - 1 with a_0 =1.

With a_1 = 5 and a_2 = 0 from the recursion formula, I came up with a_n = -9/2 * n^2 + 17/2 * n + 1. Using this formula I came up with a_3 = -14, when in reality a_3 = 22. Just a heads up.


I hope this weekend and all your future days are good to you.

Eddie


This blog is property of Edward Shore. 2013

Saturday, February 9, 2013

a_(n+1) = S * a_n + T

Hi everyone!


First a correction. In my Numerical CAS section, posted December 2012, I typed an extra quotation mark in the POLYBINE program for the Casio Prizm - that has been corrected. Much thanks to Ryan Maziarz who pointed that out to me.

Here is a link to the corrected post:
http://edspi31415.blogspot.com/2012/12/numeric-cas-part-2-binomial-expansion.html?m=1


Today we are finding the general formula for this recursion formula:

a_(n+1) = S * a_n + T

with the initial condition a_0 = A.

I could try using a characteristic polynomial, but with some observation we may be able to detected a pattern which leads us to a general formula.

Observe that:

a_0 = A

a_1 = S * a_0 + T
a_1 = S * A + T

a_2 = S * a_1 + T
a_2 = S * (S * A + T) + T
a_2 = S^2 * A + S * T + T
a_2 = S^2 * A + T * (S + 1)

a_3 = S * a_2 + T
a_3 = S * (S^2 * A + T * (S + 1)) + T
a_3 = S * A^3 + T * (S^2 + S + 1)

a_4 = S * a_3 + T
a_4 = S^4 * A + T * (S^3 + S^2 + S + 1)

From the pattern, observe that:

a_n = S^n * A + T * Σ(S^k, k=0, n-1)

With Σ(t^k, k=0, n-1) = (t^n - 1)/(t - 1) :

a_n = S^n * A + T * (S^n - S)/(S - 1)


An Example:

S = 3, T = 1, A = -2

Using the HP 39gii to generate the sequence (the 39gii uses a_1 as its initial term):


The general formula is:

a_n = (3^n) * (-2) + 1 * (3^n - 1)/(3 - 1)
a_n = (-2) * 3^n + (3^n - 1)/2
with a_0 = -2. (The 39gii has u_1 = a_0)

Example:

a_2 = u_3 = (3^2) * (-2) + (9 - 1)/2 = -14


That is all for now, see you next time!

Eddie

This blog is property of Edward Shore. 2013

5 blog entries away from the 200th blog entry.

Greetings From Monrovia! Finding a Formula to Generate the Fibonacci Sequence

Hi everyone. I am blogging from the Friends Café in downtown Monrovia, CA on a beautiful, chilly day.

Today's blog entry is about to the Fibonacci Sequence and how to find a general formula to generate a sequence.

The Fibonacci Sequence

The world famous Fibonacci Sequence, first introduced by Fibonacci's Liber Abaci, written in 1202, is:

1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 293, 377...

(Source: Pickover, Clifford. "The Math Book" Sterling Publishing, New York. 2009 - Eddie says: Go get this book - it's awesome!)

It is easy to build the sequence. Start with two entries of 1. Add them up to get the next term. Each subsequent term is the sum of the last two. 1+1=2, 1+2=3, 2+3=5, 3+5=8, 5+8=13, and so on.

We can use this recursion formula:

a_(n+2) = a_(n+1) + a_n

with the initial conditions a_0 = 1 and a_1 = 1.

We can generate a general formula for this.


Technique

Start with the recursion formula:

a_(n+2) = a_(n+1) + a_n

with the initial conditions a_0 = 1 and a_1 = 1.

This is a linear recursion formula. A way to find the general formula is to use a characteristic polynomial. The characteristic polynomial is formed by turning subscripts to exponents (and usually replacing a with another letter, such as x) and finding the roots of the polynomial.

The general formula will have the form

a_n = c_1 * (x_1)^n + c_2 * (x_2)^n + ...

Where n is the number of initial conditions.

In the case of the Fibonacci sequence, we have two initial conditions (a_0 = 1 and a_1 = 1). Hence n=2.

Then use the initial conditions to solve for the c_k constants.


Finding the General Formula

a_(n+2) = a_(n+1) + a_n
with the initial conditions a_0 = 1 and a_1 = 1.

The characteristic equation is:

x^(n+2) = x^(n+1) + x^n

Assuming x ≠ 0, divide both sides by x^n:

x^2 = x + 1

x^2 - x - 1 = 0

The roots of the polynomial are:

x_1 = (1 + √5)/2
x_2 = (1 - √5)/2

Then our general form has:

a_n = c_1 * ((1 + √5)/2)^n + c_2 * ((1 - √5)/2)^n

Our next step is to find c_1 and c_2.

Note when n = 0, a_0 = 1 and:

1 = c_1 + c_2

When n = 1, a_1 = 1 and:

1 = c_1 * (1 + √5)/2 + c_2 * (1 - √5)/2

Leaving us with the system of linear equations:

c_1 + c_2 = 1
c_1 * (1 + √5)/2 + c_2 * (1 - √5)/2 = 1

I like using matrices to solve systems of linear equations, you may a different preferred way, it's all good here:

[ [1, 1], [(1 + √5)/2, (1 - √5)/2] ] * [ [c_1], [c_2] ] = [ [ 1 ], [ 1 ] ]

[ [c_1], [c_2] ] = [ [1, 1], [(1 + √5)/2, (1 - √5)/2] ]^-1 * [ [ 1 ], [ 1 ] ]

[ [c_1], [c_2] ] = [ [(5 - √5)/10, √5/5], [(5 + √5)/10, -√5/5] ] * [ [ 1 ], [ 1 ] ]

which evaluates and simplifies to:

c_1 = (5 + √5)/10
c_2 = (5 - √5)/10

The general formula to generate the Fibonacci sequence is:

a_n = (5 + √5)/10 * ((1 + √5)/2)^n + (5 - √5)/10 * ((1 - √5)/2)^n


An approximate formula would be (8 digits):

a_n ≈ 0.72360680 * 1.6180339^n + 0.27639320 * (-0.6180339)^n

Round off when necessary.

Testing the general formula, find the 2nd and 6th term:

a_2 = (5 + √5)/10 * ((1 + √5)/2)^2 + (5 - √5)/10 * ((1 - √5)/2)^2
a_2 = (5 + √5)/5 + (5 - √5)/2
a_2 = 10/2 = 2

a_6 = (5 + √5)/10 * ((1 + √5)/2)^6 + (5 - √5)/10 * ((1 - √5)/2)^6
a_6 = (65 + 29 * √5)/10 + (65 - 29 * √5)/10
a_6 = 130/10 = 13


A Broader Problem

The technique applied can be applied to the general problem:

a_(n+2) = S * a_(n+1) + T * a_n

With initial conditions a_0 = A and a_1 = B.

Using the trusty HP 50g to assist me, I come up with the following:

a_n = c_1 * (x_1)^n + c_2 * (x_2)^n

where

x_1 = (S + √(S^2 + 4 * T))/2

x_2 = (S - √(S^2 + 4 * T))/2

c_1 = (B - A * x_2)/(x_1 - x_2)

c_2 = (A * x_1 - B)/(x_1 - x_2)


Next time, I am going to look at the general recursion formula:

a_(n+1) = S * a_n + T with the initial condition a_0 = A

I am working a basic programming series, which my target is with the HP 39gii calculator and the series would be posted in March 2013.

Thank you everyone who reads, follows, and comments on this blog. As always it is much appreciated.

Have a great day!

Eddie


This blog is property of Edward Shore. 2013

Friday, February 1, 2013

Balances and Recursion Formula - Part 2


To recap our scenario:

We have a loan with an initial balance $b, that has an annual interest rate of r%. We are making a monthly payment of $p every month. In Part 1, we were finding out how long to pay off the balance.

In Part 2, we asking the same question, but with an added component: this time assume that there is a monthly charge of $c to the balance. The charge stops when the balance is paid.


Variables:
b = a_0 = initial balance
p = monthly payment
r = annual rate
c = monthly additional charge
a_n = balance after n payments

Let the recursion formula be:

a_(n+1) = (a_n + c) + (a_n + c) × r/1200 - p
with the initial condition a_0 = b.

Let θ = r/1200, then:
a_(n+1) = (a_n + c) × (1 + θ) - p

Let's get a_1, a_2, and a_3 in terms of a_0.

a_1 = (a_0 + c) × (1 + θ) - p

a_2 = (a_1 + c) × (1 + θ) - p
a_2 = ((a_0 + c) × (1 + θ) - p + c) × (1 + θ) - p
a_2 = (a_0 + c) × (1 + θ)^2 - p × (1 + θ) + c × (1 + θ) - p

a_3 = (a_2 + c) × (1 + θ) - p
a_3 = a_2 × (1 + θ) + c × (1 + θ) - p
a_3 = ((a_0 + c) × (1 + θ)^2 - p × (1 + θ) + c × (1 + θ) - p) × (1 + θ) + c × (1 + θ) - p
a_3 = (a_0 + c) × (1 + θ)^3 - p × (1 + θ)^2 + c × (1 + θ)^2 - p × (1 + θ) + c × (1 + θ) - p

Noticing a pattern...

a_n = (a_0 + c) × (1 + θ)^n - p × Σ((1 + θ)^k, k=0, n-1) + c × Σ((1 + θ)^k, k=1, n-1)
a_n = (a_0 + c) × (1 + θ)^n - p × ((1 + θ)^n - 1)/θ + c × ((1 + θ)^n - (1 + θ))/θ

With a_0 = b:

a_n = (b + c) × (1 + θ)^n - p × ((1 + θ)^n - 1)/θ + c × ((1 + θ)^n - (1 + θ))/θ


Example 1:

Sandra has a credit card with a 15% APR. The initial balance is $1,500.00. Sandra uses a premium credit card that charges $20.00 each month there is a balance.

b = 1500.00
c = 20.00
r = 15%
p = 500.00

Then θ = 15/1200 = 1/80

The resulting sequence is:

a_0 = 1500.00
a_1 = 1039.00
a_2 = 572.23
a_3 = 99.64

In 3 payments , Sandra has knocked the balance to below the payment amount of $1,500.00. In month 4, the amount will be ($99.64 + $20.00) × (1 + 15/1200) = $121.14, and her debt will be over.

Example 2:
Greg has taken a payday loan, for the amount of $1,893.64. The interest rate is 14.99% and the loan incurs a $14.99 holding fee for each month the balance exists. Greg makes a $350.00 payment every month.

b = 1893.64
c = 14.99
r = 15.99%
p = 350.00

Then θ = 15.99/1200

The sequence generated is:

a_0 = 1893.64
a_1 = 1584.06
a_2 = 1270.36
a_3 = 952.48
a_4 = 630.36
a_5 = 303.95

At month 6, the final balance will be ($303.95 + $14.99) × (1 + 14.99/1200) = $322.92.


We can find out when the balance is zero by solving for n.

When a_n = 0:

n = ln((c × (1 + θ)/θ - p/θ) / (b + c - p/θ +c/θ)) × (ln (1 + θ))^(-1)

Then the integer part of n, int(n), is the nth payment when the balance is less than the payment amount.

Recalling our examples:

Example 1:

b = 1500.00
c = 20.00
r = 15%
p = 500.00

Then θ = 15/1200 = 1/80, and n ≈ 3.21

This means the balance is below the payment after then 3rd payment.

Example 2:

b = 1893.64
c = 14.99
r = 15.99%
p = 350.00

Then θ = 15.99/1200 and n ≈ 5.91

The balance becomes below the payment after the 5th payment.


Have a great day everyone!

Eddie

This blog is property of Edward Shore. 2013

Balances and Recursion Formula - Part 1

Greetings everyone coming to you from a Starbucks in Covina, CA! (on my way to seeing my mom and some friends for dinner).

1 month of 2013 is already in the books - hope everyone is getting February off to a great start!

The topic of this and the next post: using a recursion formula in financing.



The scenario: You have a loan that you make monthly payments. Interest accrues each month based on the loan's balance. The rate is stated as an annual rate. How many months will it take to pay off the loan?

For this, we are going to use a recursion formula to describe the balance at the end of each payment. We will then come up with a general formula which will allow us to find the balance at any month. Finally, use the general formula to find when the balance is zero (approximately).

Part 1 will deal with the scenario stated. On my next blog entry, I will consider paying the loan balance when a monthly charge is involved.


What is a recursion formula?

A recursion formula is a formula in which the result is based on previous results. To generate a sequence of answers, one or more initial conditions are required.

A simple example is:

a_(n+1) = 2 × a_n + 1 with the initial condition a_0 = 0.

In order to calculate a_(n+1), you will need the previous result, a_n.

Then: (a_n is in bold)

a_0 = 0 (start with the initial condition)
a_1 = 2 × 0 + 1 = 1
a_2 = 2 × 1 + 1 = 3
a_3 = 2 × 3 + 1 = 7
a_4 = 2 × 7 + 1 = 15
And so on...

Some recursion formulas can be transformed into general formulas, where any nth term can be found when only the initial conditions are known.

A famous recursion formula is the Fibonacci Sequence (1, 1, 2, 3, 5, 8, 13, 21, etc...)

a_(n+2) = a_(n+1) + a_n with the initial conditions a_0 = 1 and a_1 =1.


Back to our scenario: You have a loan that you make monthly payments. Interest accrues each month based on the loan's balance. The rate is stated as an annual rate. How many months will it take to pay off the loan?

Variables:
b = a_0 = initial balance
p = monthly payment
r = annual rate (if the rate is 10%, r = 10)
a_n = balance after n payments (after n months)

Let the recursion formula be:
a_(n+1) = a_n + a_n × r/1200 - p
with the initial condition a_0 = b

Let θ = r/1200. Then:

a_(n+1) = a_n × (1 + θ) - p

Note: we will stop when the balance sinks below the payment amount. At that point, the next payment is the balance, reducing the debt to 0.

Calculating the first few terms (balance after n payments) in terms of the initial balance (a_0):

a_1 = a_0 × (1 + θ) - p

a_2 = a_1 × (1 + θ) - p
a_2 = (a_0 × (1 + θ) - p) - p
a_2 = a_0 × (1 + θ)^2 - p × (1 + θ) - p

a_3 = a_2 × (1 + θ) - p
a_3 = (a_0 × (1 + θ)^2 - p × (1 + θ) - p) × (1 + θ) - p
a_3 = a_0 × (1 + θ)^3 - p × (1 + θ)^2 - p × (1 + θ) - p

Noticing the pattern...

a_n = a_0 × (1 + θ)^n - Σ( p × (1 + θ)^k, k=0, n-1)
a_n = a_0 × (1 + θ)^n - p × Σ( (1 + θ)^k, k=0, n-1)
a_n = a_0 × (1 + θ)^n - p × ((1 + θ)^n - 1)/(1 + θ - 1))

With a_0 = b:

a_n = b × (1 + θ)^n - p × ((1 + θ)^n - 1)/θ


Example 1:

A bank loan is made for $1,000, which has a 10% annual interest rate. The borrower plans to make monthly payments of $300.

r = 10%, b = 1000, p = 300
Then θ = 10/1200 = 1/120

The sequence generated is:

a_0 = 1000.00
a_1 = 708.33
a_2 = 414.23
a_3 = 117.68

Example 2:

The balance on a short term lease is currently $8,764.10. The lessor wants to make payments of $1,500 until the balance is fully paid. The lease carries an interest rate of 4.95%.

r = 4.95%, b = 8764.10, p = 1500.00
Then θ = 4.95/1200 = 33/8800

The sequence generated is:

a_0 = 8764.10
a_1 = 7300.25
a_2 = 5830.37
a_3 = 4354.42
a_4 = 2872.38
a_5 = 1384.27


When will the balance be fully paid?

Solving for n when a_n = 0:

0 = b × (1 + θ)^n - p × ((1 + θ)^n - 1)/θ
0 = (b - p/θ) × (1 + θ)^n + p/θ
-p/θ = (b - p/θ) × (1 + θ)^n
-[ (p/θ) / (b - p/θ) ] = (1 + θ)^n
[ (p/θ) / (p/θ - b) ] = (1 + θ)^n
ln [ (p/θ) / (p/θ - b) ] = n × ln (1 + θ)

n = ln [ (p/θ) / (p/θ - b) ] / ln (1 + θ)

Taking the integer portion of n, or int(n), gives the nth payment when the balance is less than the payment amount.


Continuing with our two examples from before:

Example 1:

r = 10%, b = 1000, p = 300
Then θ = 10/1200 = 1/120

n ≈ 3.3

After 3 payments, the balance is below the payment amount of $1,000.00.

Example 2:

r = 4.95%, b = 8764.10, p = 1500.00
Then θ = 4.95/1200 = 33/8800

n ≈ 5.9

After 5 payments, the balance is below the payment amount of $1,500.00.


Next time will be Part 2. Thanks as always!

Eddie


This blog is property of Edward Shore. 2013



P.S. To all those who are partaking in the Super Bowl festivities this Sunday: please be safe - and don't drink and drive! And have fun.

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...