Showing posts with label gamma function. Show all posts
Showing posts with label gamma function. Show all posts

Saturday, November 29, 2025

fx-991 CW: Gamma Function

fx-991 CW: Gamma Function



All screenshots were made with Casio’s classpad.net website.



No Gamma Function? No Problem!


The gamma function is used a lot in advanced mathematics. The gamma functions with a lot of definition functions, but the most common one is for values t>0 (in particular Re(t)>0):


Γ(t) = ∫( x^(t-1) × e^(-x) dx, 0, ∞)


This integral is an improper integral and unless we have a calculator that handles infinite limit, we need to use the following:


Γ(t) =


lim ∫( x^(t-1) × e^(-x) dx, 0, w)

w → ∞


Calculators with the integral function can use the above for estimating the gamma function.



Use Basic Properties for Shortcuts


If t is a positive integer, we can use the factorial function:


Γ(t) = (t – 1)!


Example: Γ(16) = (16 – 1)! = 15! ≈ 1.31 × 10^12



If t is in the form n/2 where n is odd (i.e. 1/2 = 0.5, 3/2 = 1.5, 5/2 = 2.5, 7/2 = 3.5, etc.). we can use the product..


Γ(n / 2) = (n – 2) / 2 × (n – 4) / 2 × (n – 6) / 2 × … × 1 / 2 × √π


Example: Γ(3.5) = Γ(7 / 2) = 5 / 2 × 3 / 2 × 1 / 2 × √π = 15 / 8 × √π ≈ 3.32335097


The following pictures demonstrate the use of the above equivalency along with integral estimate:



I hope you find this helpful,


Eddie


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


The author does not use AI engines and never will.

Saturday, December 10, 2022

HP 20S: Gamma Function Approximation (Stirling's Formula)

HP 20S:  Gamma Function Approximation (Stirling's Formula)



Introduction


The gamma function uses the approximation sequence:


Let t = x + 9


Then calculate:


Let G = Γ(t) ≈ 

exp( ln √(2 × π ÷ t) + t × ln t - t + (12 × t)^-1 - (360 × t^3)^-1 + (1260 × t^5)^-1 )


Note:

(360 × t^3)^-1  = (12 × t)^-1 × (30 × t^2)^-1

(1260 × t^5)^-1 = (360 × t^3)^-1 × (3.5 × t^2)^-1


While x > t:  

G = G ÷ x

x = x + 1

End Loop


Display G as the final answer 


The approximation polynomial is used for higher values because for the approximation is more accurate for higher values.  



HP 20S:  Gamma Approximation

(63 steps)


Key Code:  { Key }


61, 41, b :  { LBL B }

21, 1 :  { STO 1 }

75 :   { + }

9 :  { 9 }

74 : { = }

21, 2 : { STO 2 }

32 : { +/- }

21, 0 : { STO 0 }

32 : { +/- } 

55 : { × }

13 : { LN }

74 : { = }

21, 75, 0 : { STO+ 0 }

2 :  { 2 }

55 : { × }

61, 22 : { π }

45 : { ÷ }

22, 2 : { RCL 2 }

74 : { = }

11 : { √ }

13 : { LN }

21, 75, 0 : { STO+ 0 }

1 : { 1 }

2 : { 2 }

55 : { × }

22, 2 : { RCL 2 }

74 : { = }

15 : { 1/x }

21, 75, 0 : { STO+ 0 }

45 : { ÷ }

3 : { 3 }

0 : { 0 }

45 : { ÷ }

22, 2 : { RCL 2 }

51, 11 :  { x^2 }

74 : { = }

21, 65, 0 : { STO- 0 }

45 : { ÷ }

3 : { 3 }

73 : { . }

5 : { 5 }

45 : { ÷ }

22, 2 : { RCL 2 }

51, 11 : { x^2 }

74 : { = }

21, 75, 0 : { STO+ 0 }

22, 0 : { RCL 0 }

12 : { e^x }

21, 0 : { STO 0 }

61, 41, 0 : { LBL 0 }

22, 1 : { RCL 1 }

21, 45, 0 : { STO÷ 0 }

1 : { 1 }

21, 75, 1 : { STO+ 1 }

22, 2 : { RCL 2 }

31 : { INPUT }

22, 1 : { RCL 1 }

61, 42 : { x≤y? }

51, 41, 1 : { GTO 1 }

51, 41, 0 : { GTO 0 }

61, 41, 1 : { LBL 1 }

22, 0 : { RCL 0 }

61, 26 : { RTN }



Examples


Γ(0.5) returns 1.77245385109


Γ(4.4) returns 10.1361018514


Calculate the gamma function, press [ XEQ ] B. 


This program is based on the approximation code of the HP 25.  



Source:


Davidson, Jim, and John Vlissides.  "HP-25 Program-Gamma Function"  ENTER: 65 NOTES  Vol. 3 No. 10  December 1976



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. 


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. 


Monday, June 13, 2022

Retro Review: Radio Shack EC-4035

Retro Review:   Radio Shack EC-4035






Quick Facts:


Model:  EC-4035

Company:  Radio Shack

Equivalent Of:  Casio fx-580

Years:  1986-1991

Type:  Scientific

Batteries: 1 x CR-2032

Operating Mode:  AOS

Memory Registers: 7  (K1 - K6, M)

Number of Digits: 10 (display), 8 in fractions, 2 digit exponents are in the top right of the display (10^xx)

Contrast Wheel


Features


*  Trigonometry, logarithmic functions

*  Base conversions with Boolean algebra

*  Engineering and Units mode

*  Single variable and linear regression  (y = A + Bx)

*  Gamma function

*  Complex numbers

*  6 constant memories (Kin/Kout) complete with storage arithmetic


The Radio Shack EC-4035 (Casio fx-580) uses an AOS (postfix) operating mode,  instead of typing expressions as they are written.


Statistics Mode


In linear regression, the equation used is y = A + Bx, where A is the y-intercept and B is the slope.  The statistics mode uses the six constant memories as follows:


K1 = Σx^2

K2 = Σx

K3 = n

K4 = Σy^2

K5 = Σy

K6 = Σxy


Gamma Function


The EC-4035 has a gamma function (Γ), which accepts all real numbers except for negative integers (-1, -2, -3, etc, because the gamma function is undefined there).  I wish this was available on more scientific functions.  


1 [a b/c] 2 [ Γ ] returns 1.772453851  (√π).  


The factorial function (x!) still only accepts non-negative integers.  


Complex Numbers


In the complex mode (Mode 3), the available functions are:


*  arithmetic (+, -, ×, ÷)

*  reciprocal (1/x)

*  argument and absolute value 

*  conjugate (x + yi → x - yi)

*  powers and roots, x^2, √


The arrow key [ → ]  and the key sequence [ SHIFT ] ( ← ) can scroll complex numbers.   Complex numbers are entered in rectangular form.  


Units and Engineering Modes


Results and calculations can be made using Engineering units and certain Electronics symbols.  All are accessed by using the [ [Sym] ] key.  The symbol each key has is located on the bottom right of the key in navy blue.   


[ MODE ] [ . ]:  Engineering Mode.  Results are shown, when applicable, with engineering symbols, for instance:


n:  nano, 10^-9

μ:  micro, 10^-6

m:  milli, 10^-3

k:  kilo, 10^3

M:  mega, 10^6

G:  giga, 10^9


The mode can be turned off by pressing [ MODE ] [ . ].


[ MODE ] [ 0 ]:  Unit Mode.  This is an enhancement to engineering mode to add electronic units:


V:  volts

A:  amperes

S:  seconds

W:  watts

F:  farads

C:  coulombs

Ω:  ohms


The electronic units can be combined with engineering units.    Also, the appropriate unit is determined in calculations.    To leave Unit Mode, go to Comp Mode by pressing [ MODE ] [ 1 ]. 


Engineering and Unit Mode are neat modes and it's really geared for electronic engineering and physics calculations.


Final Thoughts


The features of the EC-4035 gives a pretty standard advanced scientific calculators with additional features geared towards electronic engineering.   


Perhaps the next perfect calculator for electronic engineering would be a combination of the EC-4035 (fx-580), Casio fx-61f, and Calculated Industries Electronic Calc Pro (5070).  



Source:


"casio fx-580"  Voidware.  http://www.voidware.com/calcs/fx580.htm  Last Accessed April 22, 2022. 


Until next time,


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. 


Wednesday, March 2, 2016

HP Prime and Casio fx-5800p Approximating the Factorial Function

HP Prime and Casio fx-5800p Approximating the Factorial Function

A quick way to estimate the factorial function, which is good for all real numbers (and complex numbers with the HP Prime) is determined by Gergő Nemes Ph. D (Mathematics, University of Edinburgh):

N! ≈ N^N * √(2*π*N) * e^(1/(12*N+2/(5*N+53/(42*N)))-N)

The error is the order of 1 + O(N^-8).   Like the Sterling approximation formula, this formula is a better approximation as N increases. 

Casio fx-5800p Program:  GERGO

“GERGO RSKEY.ORG”
“N”? → N
N^(N)*√(2πN)*e^(
1÷(12N+2÷(5N+53÷
(42N)))-N)

HP Prime:  GERGO

EXPORT GERGO(N)
BEGIN
// rskey.org 2016-03-02
RETURN N^N*√(2*N*π)*
e^(1/(12*N+2/(5*N+53/(42*N)))
-N);
END;

How accurate is it?

Here a test of some random values to compare accuracy.

Values

N
N! (Determined by Wolfram Alpha)
N! approximation
1.25
1.13300309631…
1.133039736
3.08
6.64025496878…
6.640255733
5
120
120.0000005
6.64
2460.94013688180…
2460.940138
8.27
72172.53628421024…
72172.53629
11.5
1.368433654655… x 10^8
136843365.5

Source:

“Sterling’s Approximation”  Wikipedia – Page February 26, 2016 https://en.wikipedia.org/wiki/Stirling%27s_approximation#cite_note-Nemes2010-10 Retrieved March 1, 2016


Toth, Viktor T.  “The Gamma Function”  R/S Programmable Calculators  http://www.rskey.org/CMS/the-library?id=11  Retrieved March 1, 2016

Thursday, May 9, 2013

Vacation! And some goodies!

Greetings from San Luis Obispo. I am on vacation this week having a great time!

So far I visited Morro Bay (what a sight - despite the presence of a power plant),hung out in downtown SLO, and visited Cal Poly (and it's library - I am going to hit the library at UC Santa Barbara tomorrow).

Some math tips I picked up from my visit:

Fuzzy sets are sets that allow degrees of membership. Instead of having a Yes/No decision of whether an object belongs in a set, degrees of acceptance are allowed.

Let A(x) → [0,1] where A(x) is the degree of acceptance.

The basic properties for normal sets work for fuzzy sets.

From the NIST Handbook of Mathematical Functions (that book is huge!):

Ways to calculate some functions:

Error Function:

erf(z) = 2/√π * ∫(e^(-t^2) dt, 0, z) = 2/√π * Σ((-1)^n * z^(2*n+1) /(n! * (2*n+1)), n=0 to infinity)

Γ(z) = ∫(e^-t * t^(z-1) dt,0,infinity) = (z-1)! = π /(sin (π*z) * Γ(1-z))

Γ(x) ≈ e^-x * x^x * √(2 π/x) * Σ(g_k/x^k, k=0 to infinity) where g_k is from a series. The first few terms are

g_1 = 1
g_2 = 1/12
g_3 = 1/288
g_4 = -139/51840
g_5 = -571/2488320
g_6 = 163879/2090188880

zeta(s) = Σ(n^-s, n=0 to infinity) = 2^(s-1)/Γ(s+1) * ∫(x^s/(sinh x)^2 dx, 0, infinity)
= 1/Γ(s) * ∫(x^(s-1)/(e^x - 1) dx, 0, infinity)


Wishing the best for everyone,

Eddie


DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues The programs are listed for the Swiss Micros DM42 an...