有什么有效的方法来计算第 n 项的调和级数之和? 1 + 1/2 + 1/3 + --- + 1/n =?

发布于 2024-09-20 00:18:39 字数 1459 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

玉环 2024-09-27 00:18:47
function do(int n) 
{
    if(n==1)
        return n;

    return 1/n + do(--n); 
}
function do(int n) 
{
    if(n==1)
        return n;

    return 1/n + do(--n); 
}
冬天的雪花 2024-09-27 00:18:45

如果我正确理解你的问题,阅读本文应该对你有帮助: http://en.wikipedia.org/wiki /Harmonic_number

If I understood you question correctly, reading this should help you: http://en.wikipedia.org/wiki/Harmonic_number

丑疤怪 2024-09-27 00:18:43

由于它是调和级数,总和为n,您正在寻找第 n 个谐波数,大约由下式给出γ + ln[n],其中 γ欧拉-马斯切罗尼常数

对于较小的n,直接计算总和即可:

double H = 0;
for(double i = 1; i < (n+1); i++) H += 1/i;

As it is the harmonic series summed up to n, you're looking for the nth harmonic number, approximately given by γ + ln[n], where γ is the Euler-Mascheroni constant.

For small n, just calculate the sum directly:

double H = 0;
for(double i = 1; i < (n+1); i++) H += 1/i;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文