|
i figured this would be answered immediately with full details, but
here is a little help. the next term is also negative, and with a
much larger denominator. most of the series i saw were for log(gamma(1+x)).
at least one promised 7 significant digits from 9(i think) terms.
to get the best advice, tell us what accuracy you need, and for what
range of argument. also, do you have constraints on the error?
for instance, min value of max error, or min average error over what range.
do you have a math library, or are you restricted to an algebraic expansion?
|
| > However I can't understand where the 4th term comes from (the one with
> 139 as the numerator), nor can I work out what *should* be the next
> term.
571
Me neither, but the next term is - ---------------------
2488320 * x^4
Doncha just hate it when somebody gives you an infinite series without
bothering to explain where the coefficients come from?
John
|
| There is a better way to calculate gamma - that's to calculate
log(gamma) instead, and then exponentiate to get gamma itself.
One reason is that the the asymptotic series is more accurate for
a given number of terms, and only has odd powers of 1/x^k in the
expansion, and also that the coefficients have a very simple form
in terms of Bernoulli numbers so you can in principle have as many
terms as you want.
The mysterious coefficients in the series you give come from
exponentiating the series for log(gamma), (known in terms of
Bernoulli numbers) by formal power series manipulation. There
is no simple closed form for them.
Also, the series is asymptotic - this means that accuracy for a
given number of terms in the series increases as x increases, but
does *not* mean that for a given x, you adding more terms to the
series increases accuracy without limit. In fact, accuracy gets worse
after a point in the series!
A simple "fix" for this last problem is to use the relation
gamma(z+1) = z*gamma(z)
and work backwards to get an accurate gamma for a small number.
For example, suppose you want gamma(4.5). Since the series is
more accurate for larger x, instead calculate gamma(10.5) (say)
and then use
gamma(10.5) = 9.5*8.5*7.5*6.5*5.5*4.5*gamma(4.5)
to find gamma(4.5).
This is now the multiprecision package "MP" calculates gamma to
arbitrary precision.
- Jim
|