Topic: 怎么计算100阶程

  Print this page

1.怎么计算100阶程 Copy to clipboard
Posted by: fgh520
Posted on: 2006-03-21 11:27

怎么计算100阶程.谢谢了.
急用.

2.Re:怎么计算100阶程 [Re: fgh520] Copy to clipboard
Posted by: fgh520
Posted on: 2006-03-21 11:30

用BigInteger.怎么写呢?斑竹.
麻烦你一下.再次谢谢了.

3.Re:怎么计算100阶程 [Re: fgh520] Copy to clipboard
Posted by: floater
Posted on: 2006-03-21 12:17

use gamma function

4.Re:怎么计算100阶程 [Re: fgh520] Copy to clipboard
Posted by: why
Posted on: 2006-03-21 12:21

敝人不知100阶程是啥, factorial?

http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html

// BigInteger only has methods to deal with a String or a long value, the latter is used
public BigInteger factorialBigInteger(long n) {
BigInteger bi = BigInteger.valueOf(2L);
for (long i = 3L; i <= n; i++) {
bi = bi.multiply(BigInteger.valueOf(i));
}
return bi;
}


閣下可以試試寫一個recursive的method

5.Re:怎么计算100阶程 [Re: floater] Copy to clipboard
Posted by: why
Posted on: 2006-03-21 12:33

floater wrote:
use gamma function

gamma(n+1) = n!
but does BigInteger has a gamma method?Question

6.Re:怎么计算100阶程 [Re: fgh520] Copy to clipboard
Posted by: floater
Posted on: 2006-03-21 12:44

Up to what you want:

import org.apache.commons.math.special.Gamma;

public class MyGammaTest
{
public static void main(String[] args)
{
double x = 101.0d;
double y = Math.exp(Gamma.logGamma(x));
System.out.println(y);
}
}

9.332621544394225E157

check this java doc. The reason we use 101 is in the reference.
http://jakarta.apache.org/commons/math/apidocs/org/apache/commons/math/special/Gamma.html

7.Re:怎么计算100阶程 [Re: floater] Copy to clipboard
Posted by: why
Posted on: 2006-03-21 22:17

floater wrote:
check this java doc. The reason we use 101 is in the reference.
http://jakarta.apache.org/commons/math/apidocs/org/apache/commons/math/special/Gamma.html

I see.
But a version for BigInteger is requested now.

8.Re:怎么计算100阶程 [Re: fgh520] Copy to clipboard
Posted by: floater
Posted on: 2006-03-22 03:17

yea, you are right.

9.Re:怎么计算100阶程 [Re: fgh520] Copy to clipboard
Posted by: fgh520
Posted on: 2006-03-22 11:43

真是太感谢你们了.让我学到了不少啊.
谢谢以上的朋友,能够抽出时间,给我回帖.
希望我们以后经常交谈.向你们学习..
我刚开始学习java,所以有很很多地方不懂.
以后可能还要麻烦大家了.thanks a lot!!!!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923