%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function res=ratio(nsim); res=zeros(1,nsim); for i=(1:nsim) res(i)=(prod(1:i))/(i^i); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Output from ratio for 10 first integers: >> ratio(10) ans = Columns 1 through 7 1.0000 0.5000 0.2222 0.0938 0.0384 0.0154 0.0061 Columns 8 through 10 0.0024 0.0009 0.0004 %These become extremely small, so we consider %the logs to see what is happening >> log(ratio(100)) ans = Columns 1 through 7 0 -0.6931 -1.5041 -2.3671 -3.2597 -4.1713 -5.0962 Columns 8 through 14 -6.0309 -6.9732 -7.9214 -8.8745 -9.8317 -10.7922 -11.7556 Columns 15 through 21 -12.7215 -13.6896 -14.6596 -15.6312 -16.6045 -17.5790 -18.5548 Columns 22 through 28 -19.5318 -20.5097 -21.4886 -22.4683 -23.4488 -24.4301 -25.4120 Columns 29 through 35 -26.3945 -27.3777 -28.3614 -29.3456 -30.3303 -31.3154 -32.3010 Columns 36 through 42 -33.2870 -34.2734 -35.2601 -36.2471 -37.2345 -38.2222 -39.2102 Columns 43 through 49 -40.1985 -41.1871 -42.1759 -43.1649 -44.1542 -45.1437 -46.1335 Columns 50 through 56 -47.1234 -48.1135 -49.1038 -50.0943 -51.0850 -52.0759 -53.0669 Columns 57 through 63 -54.0581 -55.0494 -56.0409 -57.0325 -58.0243 -59.0162 -60.0082 Columns 64 through 70 -61.0003 -61.9926 -62.9850 -63.9775 -64.9701 -65.9628 -66.9556 Columns 71 through 77 -67.9485 -68.9416 -69.9347 -70.9279 -71.9212 -72.9146 -73.9081 Columns 78 through 84 -74.9016 -75.8953 -76.8890 -77.8828 -78.8767 -79.8706 -80.8647 Columns 85 through 91 -81.8588 -82.8529 -83.8471 -84.8414 -85.8358 -86.8302 -87.8247 Columns 92 through 98 -88.8193 -89.8139 -90.8085 -91.8032 -92.7980 -93.7928 -94.7877 Columns 99 through 100 -95.7827 -96.7776 %There seems to be a linear dependence on $n$ here, %we try dividing by n at each step: >> log(ratio(100))./(1:100) ans = Columns 1 through 7 0 -0.3466 -0.5014 -0.5918 -0.6519 -0.6952 -0.7280 Columns 8 through 14 -0.7539 -0.7748 -0.7921 -0.8068 -0.8193 -0.8302 -0.8397 Columns 15 through 21 -0.8481 -0.8556 -0.8623 -0.8684 -0.8739 -0.8790 -0.8836 Columns 22 through 28 -0.8878 -0.8917 -0.8954 -0.8987 -0.9019 -0.9048 -0.9076 Columns 29 through 35 -0.9102 -0.9126 -0.9149 -0.9170 -0.9191 -0.9210 -0.9229 Columns 36 through 42 -0.9246 -0.9263 -0.9279 -0.9294 -0.9309 -0.9322 -0.9336 Columns 43 through 49 -0.9348 -0.9361 -0.9372 -0.9384 -0.9395 -0.9405 -0.9415 Columns 50 through 56 -0.9425 -0.9434 -0.9443 -0.9452 -0.9460 -0.9468 -0.9476 Columns 57 through 63 -0.9484 -0.9491 -0.9498 -0.9505 -0.9512 -0.9519 -0.9525 Columns 64 through 70 -0.9531 -0.9537 -0.9543 -0.9549 -0.9554 -0.9560 -0.9565 Columns 71 through 77 -0.9570 -0.9575 -0.9580 -0.9585 -0.9589 -0.9594 -0.9598 Columns 78 through 84 -0.9603 -0.9607 -0.9611 -0.9615 -0.9619 -0.9623 -0.9627 Columns 85 through 91 -0.9630 -0.9634 -0.9638 -0.9641 -0.9644 -0.9648 -0.9651 Columns 92 through 98 -0.9654 -0.9657 -0.9660 -0.9663 -0.9666 -0.9669 -0.9672 Columns 99 through 100 -0.9675 -0.9678 %Looks like this tends to -1, (roughly)This means:

Or

In fact there is a term in *n* left because the ratio of this
approximation to *n*! still increases (in fact like .

The true approximation is given by Stirling's formula which uses the notion of asymptotically equivalent.

Definition:

Two sequences *a*_{k} and *b*_{k} are said to
be asymptotically equivalent if

Theorem 1:(Stirling's Formula)

Factorial n is asymptotically equivalent to
the sequence defined as:
.

Here is the file stirling.m:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function res=stirling(nsim) res=zeros(1,nsim); for i=(1:nsim) res(i)=(i/exp(1))^i*i^(1/2)*sqrt(2*pi)/prod(1:i); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%This gives the following series of ratios showing that the approximation gets progressively better:

>> stirling(100) ans = Columns 1 through 7 0.9221 0.9595 0.9727 0.9794 0.9835 0.9862 0.9882 Columns 8 through 14 0.9896 0.9908 0.9917 0.9925 0.9931 0.9936 0.9941 Columns 15 through 21 0.9945 0.9948 0.9951 0.9954 0.9956 0.9958 0.9960 Columns 22 through 28 0.9962 0.9964 0.9965 0.9967 0.9968 0.9969 0.9970 Columns 29 through 35 0.9971 0.9972 0.9973 0.9974 0.9975 0.9976 0.9976 Columns 36 through 42 0.9977 0.9978 0.9978 0.9979 0.9979 0.9980 0.9980 Columns 43 through 49 0.9981 0.9981 0.9981 0.9982 0.9982 0.9983 0.9983 Columns 50 through 56 0.9983 0.9984 0.9984 0.9984 0.9985 0.9985 0.9985 Columns 57 through 63 0.9985 0.9986 0.9986 0.9986 0.9986 0.9987 0.9987 Columns 64 through 70 0.9987 0.9987 0.9987 0.9988 0.9988 0.9988 0.9988 Columns 71 through 77 0.9988 0.9988 0.9989 0.9989 0.9989 0.9989 0.9989 Columns 78 through 84 0.9989 0.9989 0.9990 0.9990 0.9990 0.9990 0.9990 Columns 85 through 91 0.9990 0.9990 0.9990 0.9991 0.9991 0.9991 0.9991 Columns 92 through 98 0.9991 0.9991 0.9991 0.9991 0.9991 0.9991 0.9992 Columns 99 through 100 0.9992 0.9992