﻿ How to plot the gamma function

# Ken Ward's Mathematics Pages

## Series: How to plot the Gamma Function

Series Contents

### Page Contents

We seek to compute the values of gamma and produce a graph:

Note: The tables on this page are to illustrate calculating gamma values, not for reference. Although the gamma values are believed accurate to 5 decimals, they are often shown to 6 because they are meant to illustrate the use of the Stirling Approximation.

## The Basic Formulae

We are seeking a formula for gamma in terms of factorials. We wish to use Stirling's approximation to calculated the factorials, so we want to be able to use large factorials.

We will start with the following formulae, which have been derived elsewhere.

[1.02] (derived from: BinomialCoefficientsGamma.htm#[4.01] )

## A Closed Formula For Γ(x)

When we have no values for gamma, we need to calculate them using a closed formula.

By writing x=x+n in [1.01], we obtain:

[1.03]

By recursively applying [1.01], we obtain:

[1.04]

Because Γ(n+x+1)=(x+n)!, we can write [1.04] as:

[1.05]

We therefore have a closed formula for gamma. This is the same formula that was derived here. In the formula, we also have an arbitrary n which we can make sufficiently large to give us the accuracy we require when applying Stirling's Approximation

[2.01 repeated here]

(n+x) must be at least one and the factors must not be zero. However, if we know the value of (n+x)!, it can be negative

For instance, when x=4 and n=2, we have Γ(4)=6!/(4·5·6)=3·2·1, as expected.

### Making a Basic Table of Gamma Values

If we have a basic table of gamma values, we can use this to calculate other gamma values with the same increment or step value. I chose 0.05, but using a spreadsheet, it is easy to use a much smaller step than this, if we had need of it.

We can calculate gamma to any accuracy we choose (arbitrary precision) by choosing a sufficiently large n. I chose 20. The table is accurate to approximately 5 decimal places. The table contains the raw data for comparison purposes.

They are called 'basic' values because they form the basis of calculating other values.

Gamma         Stirling Corrections (Add to Stirling Factorial
x n n+1 √(2·π·(n+1) Stirling Factorial
=((n+1)/e)n·√(2·π·(n+1)
+1/(12·n) +1/(288·n2 ) Gamma x Value
0.00
0.05 20 20.05 11.223986 2817967749445040000 11712251660203800 24339675104330 19.470091784
0.10 20 20.10 11.237972 3278005144267250000 13590402754010100 28172476687417 9.513510838
0.15 20 20.15 11.251941 3813606825253560000 15771740385664000 32613193518743 6.220274911
0.20 20 20.20 11.265893 4437258676401800000 18305522592416700 37758916238483 4.590845205
0.25 20 20.25 11.279827 5163521590693230000 21249060044005100 43722345769558 3.625611078
0.30 20 20.30 11.293744 6009378240916120000 24669040397849400 50634319371612 2.991569946
0.35 20 20.35 11.307644 6994638116543560000 28643071730317600 58646748014573 2.546147787
0.40 20 20.40 11.321527 8142410668407310000 33261481488591900 67936032452189 2.218160244
0.45 20 20.45 11.335393 9479658073805080000 38629413503688200 78707036478582 1.968137017
0.50 20 20.50 11.349242 11037841090658000000 44869272726251900 91197708793195 1.772454402
0.55 20 20.55 11.363074 12853673759298200000 52123575666253800 105684459988349 1.616124768
0.60 20 20.60 11.376890 14970005391687600000 60558274238218600 122488418766623 1.489192705
0.65 20 20.65 11.390688 17436851427548500000 70366632072431200 141982712010555 1.384795523
0.70 20 20.70 11.404470 20312598413771700000 81773745627100300 164600937252617 1.298055725
0.75 20 20.75 11.418235 23665412669932000000 95041817951534000 190847023999064 1.225417070
0.80 20 20.80 11.431984 27574887247081000000 110476311086062000 221306712912784 1.164230060
0.85 20 20.85 11.445716 32133967696265600000 128433124285634000 256660919835400 1.112484066
0.90 20 20.90 11.459432 37451204086402800000 149326970041479000 297701295935962 1.068629016
0.95 20 20.95 11.473131 43653384823073700000 173641148858686000 345348346974316 1.031453618
1.00 20 21.00 11.486814 50888617325509700000 201938957640912000 400672535001809 1.000000289

## Calculating Higher Values of gamma from Γ(x)

After calculating a number of gamma values in a given range, we can use these values to find the values of higher gamma. By higher, I mean greater in magnitude. So as we have a basic table for 0-1, the higher values are 2, 3, 4, etc.

By using [1.01] when x=x+n−1, we note:

[2.01]

By applying [1.01] recursively, we find:

[2.02]

For instance, a trivial example, n=3 and x=1, Γ(4)=3·Γ(3)=3·2·1, as before.

However, for creating a table after we have found an initial set of values, all we need is:

[1.01 repeated]

We can use this formula when x≠0.

The values in the following table are calculated using [1.01]. The first values on the left come from table 1.

Table 2: Higher Gamma Values
x Γ(x) x Γ(x) x Γ(x) x Γ(x)
0.00 =infinity 1 1 2 1 3.00 2
0.05 19.47 1.05 0.973504589 2.05 1.022179819 3.05 2.0954686
0.10 9.5135 1.10 0.951351084 2.10 1.046486192 3.10 2.197621
0.15 6.2203 1.15 0.933041237 2.15 1.072997422 3.15 2.3069445
0.20 4.5908 1.20 0.918169041 2.20 1.101802849 3.20 2.4239663
0.25 3.6256 1.25 0.90640277 2.25 1.133003462 3.25 2.5492578
0.30 2.9916 1.30 0.897470984 2.30 1.166712279 3.30 2.6834382
0.35 2.5461 1.35 0.891151725 2.35 1.203054829 3.35 2.8271788
0.40 2.2182 1.40 0.887264098 2.40 1.242169737 3.40 2.9812074
0.45 1.9681 1.45 0.885661658 2.45 1.284209404 3.45 3.146313
0.50 1.7725 1.50 0.886227201 2.50 1.329340802 3.50 3.323352
0.55 1.6161 1.55 0.888868622 2.55 1.377746365 3.55 3.5132532
0.60 1.4892 1.60 0.893515623 2.60 1.429624997 3.60 3.717025
0.65 1.3848 1.65 0.90011709 2.65 1.485193199 3.65 3.935762
0.70 1.2981 1.70 0.908639007 2.70 1.544686313 3.70 4.170653
0.75 1.2254 1.75 0.919062803 2.75 1.608359904 3.75 4.4229897
0.80 1.1642 1.80 0.931384048 2.80 1.676491287 3.80 4.6941756
0.85 1.1125 1.85 0.945611456 2.85 1.749381194 3.85 4.9857364
0.90 1.0686 1.90 0.961766114 2.90 1.827355617 3.90 5.2993313
0.95 1.0315 1.95 0.979880937 2.95 1.910767827 3.95 5.6367651
1.00 1 2.00 1.000000289 3.00 2.000000579 4.00 6.0000017

## Calculating Lower Values of Gamma from Γ(x)

With our list of gamma values in a given range, we seek a formula to compute those in lower ranges. This is just our previous formula, [2.02], with Γ(x) made the subject:

[3.01]

For instance, x=4, n=3, Γ(4)=6!/(4·5·6)=3·2·1, as before.

We can use the formula [3.01] to compute Γ(−1.5), by setting n=2 and x=−1.5:

Γ(−1.5)=Γ(2−1.5)/((−1.5)·(−0.5))

=Γ(1/2)/(0.75)

=2.363272 (six decimals)

However, we can use [1.01] with negative gamma (except negative integers and zero). So we can use the easy formula, when we know Γ(x+1):

[1.01b, repeated]

The first two columns are from the basic values, written in descending order.  The reason becomes apparent from the formula:

Γ(-0.05)=Γ(-0.05+1)/(-0.05). So we compute Γ(-0.05) from Γ(0.95)

Lower Gamma Values
x Γ(x) x Γ(x)=Γ(x+1)/x x Γ(x)=Γ(x+1)/x x Γ(x)=Γ(x+1)/x x Γ(x)=Γ(x+1)/x x Γ(x)=Γ(x+1)/x
1.00 1 0 -1.00 -2.00 -3.00 -4.00
0.95 1.031454 -0.05 -20.62907235 -1.05 19.646736 -2.05 -9.583773 -3.05 3.142221 -4.05 -0.775857
0.90 1.068629 -0.10 -10.68629016 -1.10 9.714809 -2.10 -4.626100 -3.10 1.492290 -4.10 -0.363973
0.85 1.112484 -0.15 -7.416560439 -1.15 6.449183 -2.15 -2.999620 -3.15 0.952260 -4.15 -0.229460
0.80 1.164230 -0.20 -5.821150302 -1.20 4.850959 -2.20 -2.204981 -3.20 0.689057 -4.20 -0.164061
0.75 1.225417 -0.25 -4.90166828 -1.25 3.921335 -2.25 -1.742815 -3.25 0.536251 -4.25 -0.126177
0.70 1.298056 -0.30 -4.326852416 -1.30 3.328348 -2.30 -1.447108 -3.30 0.438518 -4.30 -0.101981
0.65 1.384796 -0.35 -3.956558638 -1.35 2.930784 -2.35 -1.247142 -3.35 0.372281 -4.35 -0.085582
0.60 1.489193 -0.40 -3.722981763 -1.40 2.659273 -2.40 -1.108030 -3.40 0.325891 -4.40 -0.074066
0.55 1.616125 -0.45 -3.591388373 -1.45 2.476820 -2.45 -1.010947 -3.45 0.293028 -4.45 -0.065849
0.50 1.772454 -0.50 -3.544908804 -1.50 2.363273 -2.50 -0.945309 -3.50 0.270088 -4.50 -0.060020
0.45 1.968137 -0.55 -3.578430941 -1.55 2.308665 -2.55 -0.905359 -3.55 0.255031 -4.55 -0.056051
0.40 2.218160 -0.60 -3.69693374 -1.60 2.310584 -2.60 -0.888686 -3.60 0.246857 -4.60 -0.053665
0.35 2.546148 -0.65 -3.917150441 -1.65 2.374031 -2.65 -0.895861 -3.65 0.245441 -4.65 -0.052783
0.30 2.991570 -0.70 -4.273671351 -1.70 2.513924 -2.70 -0.931083 -3.70 0.251644 -4.70 -0.053541
0.25 3.625611 -0.75 -4.834148104 -1.75 2.762370 -2.75 -1.004498 -3.75 0.267866 -4.75 -0.056393
0.20 4.590845 -0.80 -5.738556506 -1.80 3.188087 -2.80 -1.138602 -3.80 0.299632 -4.80 -0.062423
0.15 6.220275 -0.85 -7.317970484 -1.85 3.955660 -2.85 -1.387951 -3.85 0.360507 -4.85 -0.074331
0.10 9.513511 -0.90 -10.5705676 -1.90 5.563457 -2.90 -1.918433 -3.90 0.491906 -4.90 -0.100389
0.05
 19.4701
-0.95 -20.49483346 -1.95 10.510171 -2.95 -3.562770 -3.95 0.901967 -4.95 -0.182216
0.00 -1.00 -2.00 -3.00 -4.00 -5.00
Γ(x.5): Calculated from π
 1.77245
-3.544907702 2.363271801 -0.945309 0.270088 -0.06002
Error: 5.5E-07 -1.1E-06 7.4E-07 -2.9E-07 8.4E-08 -1.9E-08

Ken Ward's Mathematics Pages

# Faster Arithmetic - by Ken Ward

Ken's book is packed with examples and explanations that enable you to discover more than 150 techniques to speed up your arithmetic and increase your understanding of numbers. Paperback and Kindle:
Buy now at Amazon.com