Jump to content
xisto Community


Recommended Posts

Here is my 2nd Code:
By this class you can calculate FACTORIAL of a number:

<?phpclass factorial_math {function factorial($num) {if (($num == 0)||($num == 1)) { return 1; } else {return $num*$this->factorial($num-1);} }function calculating_e() {$iterations = 15;$fact = 1;for ($n=1; $n<=$iterations; $n++) {$fact = $fact*$n;$chan = 1/$fact;$result = $result + $chan; }return $result+1; } }// example$fuct = new factorial();print($fuct->factorial(10));?>


Share this post

Link to post
Share on other sites

This function is only working with natural numbers (0..infinity)

For this range your function is working fine.


But this could not calculate all the real numbers like -6, -8.323, 0.5 etc.


If you go to Mathematical Department in university or Mechanical Engineering or Electric-Electronic Engineering in the lesson Differential Equations or Laplace, you must learn that we have learnt the factorial function wrong before.


Until high school the teachers teach us wrong that factorial works with only 0,1,2...infinity.


Actually factorial works with all real numbers.


For example:

factorial(2) = 2

factorial(4) = 24

factorial(5) = 120

and also

factorial(1/2)=factorial(0.5)= sqrt(pi) =~ 1,77245385


If you don't believe me go to a mathematic professor in a university and ask him, factorial(1/2)?


By the way the formula of factorial is


n! = integral[0 to infinity] (t^(n-1)) * e^(-t) * dt


I couldn't write the integral symbol so I wrote: integral[0 to infinity]

I found a picture from wikipedia

Posted Image


//Edit reason: the formula inserted

Edited by Erdemir (see edit history)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.