PDA

Click to See Complete Forum and Search --> : Non-Integer Factorials


Dreamlax
May 28th, 2001, 08:23 PM
Is there a function in VB which does factorials? Currently I am using a loop which just multiplies itself by the loop counter.

I am unsure how to calculate a factorial of a non-integer. Can anyone help me?

Thanks

kedaman
May 30th, 2001, 02:32 AM
no you are doing it the right way, factorials are only defined for positive integers and 0! which is 1 which is also the aritmetic multiplication identity.

Dreamlax
May 30th, 2001, 05:37 AM
I thought that's how. But any ideas on non integer factorials? A lot of people say they can't be done, but they can. My friend once told me you have to use the 'gamma' function, whatever that is... And plus the Windows Calculator does it with a bit of struggle.

Guv
Jun 7th, 2001, 08:23 PM
Factorials are only defined for integers.

The Gamma function of positive integers is a factorial. Actually it is something like Gamma(n) = Factorial(n+1) or maybe Gamma(n) = Factorial(n-1). I forget which. I do remeber that Gamma(n+1) = n*Gamma(n), and that the Gamma function is the integral from zero to infinity of some function involving exponentials. It can be looked up in a good math library and an internet search might turn up an article or two.

Due to the relation between the Gamma function and factorials, some erroneously say that the Gamma function defines non integer factorials. Making such a statement is not illegal, immoral, or fattening, merely contrary to standard mathematical usage.

I suppose that some lord high grand guru committee of mathematicians could have defined the Gamma function as the factorial function, but they did not.

Besides, if they had defined it that way, each formula for combinations, permutations, et cetera would require a footnote stating that the formula was not valid for non integer factorials.

thinktank
Jun 8th, 2001, 05:29 AM
Can anyone help me expand

(x+a)^(1/2)

using Binomial theorem ?

Guv
Jun 8th, 2001, 06:59 AM
I think the binomial expansion is only defined for positive integers, with the kth term being the following. C(n, k) * x^k * a^(n-k)Where C(n, k) is n! / ( k! * (n -k)! )

As noted in previous posts to this thread, the factorial function is only defined for integers.

There is an algorithm for the binomial expansion which does not use factorials, but I suspect that it is not applicable. The first term is (x^n*a^0). Then determine succeeding terms as follows. Decrease the exponent of x by one. Increase the exponent of a by one. Determine coefficient by multiplying preceding coefficient by preceding exponent of x and dividing by the number of preceding terms.For positive integers, the above will result in ordinary binomial expansion. Otherwise, it results in an infinite series. Not sure if the infinite series is meaningful.

If you consider x to be variable and a to be a constant, you could try a Taylor (I think this is the name for it) series expansion. This requires using derivatives and would also be an infinite series.

pranavdesai
Jun 14th, 2001, 03:41 PM
Well basically a gamma function can be defined a s
integral having limits from o to infinity and the function inside the integral being e raised to -x multiplied with x raised to n-1 where x is any variable
here we get the valeu of gamma n
gamma(n)= (n-1)multiplied with gamma(n-1)
where n is a natural no it can be written as
gamma(n) = n-1!
if at all u had placed ur question in a more clearer manner.like whether u wanted to calculate factorial of -ve integer or a fraction i could have maybe helped u. even so if u need help on factorials or gamma fns u can email me at pranavdesai@hotmail.com
or contact me on msn messenger on the same id

Dreamlax
Jun 15th, 2001, 02:16 AM
Well, that about wraps things up. I've found everything about the Gamma function that I need to know. THanks to all who contributed to this post. :)

lluis_escude
Jun 15th, 2001, 05:25 AM
Hi,

My contribution to the factorials of non-integer numbers.
Here are 2 recipes.

First, for large numbers, use this series
(the larger x is, the better the formula works):

x! = (x^x) * exp(-x) * sqrt(2*PI*x) * (a0 + a1*(x^-1) + a2*(x^-2) + a3*(x^-3) + a4*(x^-4) + ...)

where:

a0 = 1
a1 = 1/12
a2 = 1/288
a3 = 139/51840
a4 = 571/2488320
etc

I can't remember how these coefficients are calculated,
I'd have to take a look at my math class notes from the happy? old days.

Also remember that to perform calculations with very large numbers,
say, exp(-5000) that your handheld calculator probably can't handle
(overflow!), you can express the result as a power of 10 in the
following fashion:

exp(-5000) = 10^(-5000/ln(10)) = 10^(-5000/2.303) =
10^(-2171.472) = 10^(-2171-.472) = 10^(-2171) * 10^(-.472) =
0.337 * 10^(-2171)

...ln being the neperian (base "e") logarithm.
For 5000^5000 you'd have to work out something similar.

Now, for the smaller numbers.
Assume you want x!
First calculate y! such that

x! = x * (x-1) * (x-2) * ... * y
and
0 <= y <= 1

(for example, to compute 7.3! you'd start by calculating 0.3!
and would then multiply 7.3! = 7.3 * 6.3 * ... * 0.3)

and to compute y! you can use this polynomial fit:

y! = a0 + a1*x + a2*x^2 + ... + a8*x^8 =
a0 + x(a1 + x(a2 + ... x(a7 + x*a8)...)

and the coefficients are:

a0 = 1
a1 = -.577191652
a2 = .988205891
a3 = -.897056937
a4 = .918206857
a5 = -.756704078
a6 = .482199394
a7 = -.193527818
a8 = .035868343

I have found it works very nicely.

Dreamlax
Jun 15th, 2001, 07:29 PM
Thanks for that, especially about how to deal with large numbers. Thanks again to all who have contributed, and lluis_escude for that nice big post up there.

lluis_escude
Jun 19th, 2001, 03:25 AM
In my previous post, the line

" ...and would then multiply 7.3! = 7.3 * 6.3 * ... * 0.3) "

should actually read

" ...and would then multiply 7.3! = 7.3 * 6.3 * ... * 0.3!) "

which was probably obvious to everybody.

Greetings from the warm Mediterranean...

Dreamlax
Jun 19th, 2001, 11:00 PM
I picked that up, but I thought everyone else would too...

lluis_escude
Jun 26th, 2001, 06:39 AM
Yet another formula, now for negative numbers.

(-x!)=(PI*x)/[x!*sin(PI*x)]

In the case of negative integers, the factorial goes to infinity.
Also, bear in mind the angle expressed by PI*x is in radians, not in degrees.