Sunday, August 14, 2022

TI 84 Plus CE TI-Basic and TI Nspire CX II Python: Gamma by Multiplication Recursion Property

TI 84 Plus CE TI-Basic and TI Nspire CX II Python:   Gamma by Multiplication Recursion Property


Introduction


The program calculates the gamma function for any real positive number in tenths by the multiplication recursion:


Γ(x + 1) = x * Γ(x)


For example:  


Γ(2.5)

= 1.5 * Γ(1.5)

= 1.5 * 0.5 * Γ(0.5)

≈ 1.5 * 0.5 * 1.772453851

≈ 1.329340388


Reduce x by 1 until 1 is in between 0.1 and 1. 


Gamma Values:


Γ(0.1) = 9.513507699

Γ(0.2) = 4.590843712

Γ(0.3) = 2.991568988

Γ(0.4) = 2.218159544

Γ(0.5) = 1.772453851

Γ(0.6) = 1.489192249

Γ(0.7) = 1.298055333

Γ(0.8) = 1.164229714

Γ(0.9) = 1.068628702

Γ(1) = 1


TI-84 Plus CE Program: GAMMATEN

TI-Basic


Notes:


*  To get the small L to create lists with custom names, get the character with the key strokes:  [ 2nd ] ( list ), OPS, B.  L.   In this listing, I will write L^ to symbolize the lower case L.


* L^TEN is a custom list.


Program listing:


{9.513507699, 4.590843712, 2.991568988, 

2.218159544, 1.772453851, 1.489192249,

1.298055333, 1.164229714, 1.068628702

1}→L^TEN

ClrHome

Disp "GAMMA X (NEAREST 0.1)"

Input "X≥0.1, X?",X

round(X,1)→X

fPart(X)*10→F

If F=0:10→F

1→G

While X>1

G*(X-1)→G

X-1→X

End

G*L^TEN(F)→G

Disp "EST. GAMMA: ", G


TI-NSpire Python Script:  gammaten.py


The code is defined as a function.   


def gammaten(x):

  lten=[9.513507699]

  lten.append(4.590843712)

  lten.append(2.991568988)

  lten.append(2.218159544)

  lten.append(1.772453851)

  lten.append(1.489192249)

  lten.append(1.298055333)

  lten.append(1.164229714)

  lten.append(1.068628702)

  lten.append(1)

  #print("gamma(x) to the nearest 0.1")

  x=round(x,1)

  f=round(10*(x-int(x))-1)

  g=1

  while x>1:

    x-=1

    g*=x

  g*=lten[f]

  return [g,f]


# list[-1] gets last item too

# round integers for accurate results!

# 2022-06-13 EWS


Eddie 


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


TI 84 Plus CE: Consolidated Debts

TI 84 Plus CE: Consolidated Debts   Disclaimer: This blog is for informational and academic purposes only. Financial decisions are your ...