How to find Euler's Constant

조회 수: 5 (최근 30일)
christina andrews
christina andrews 2016년 2월 9일
편집: John D'Errico 2016년 2월 9일
I am very new to MATLAB and need to program this formula:
gamma = lim m -> inf [sum k=1 to m((1/k) - ln(m + .5)]
I'm not sure how to simultaneously compute a limit and a summation simultaneously.
I tried: euler = limit(sum((1/k)-ln(m+.5)), k = 1..m), m, inf)
but it isn't working.

채택된 답변

John D'Errico
John D'Errico 2016년 2월 9일
편집: John D'Errico 2016년 2월 9일
To 50 digits, here is the value of the Euler-Mascheroni constant
0.57721566490153286060651209008240243104215933593992
Computing it is just a loop. Compute the sum of 1/k.
tic
format long g
C = 0;
for k = 1:1e9
C = C + 1/k;
end
toc
C - log(k+0.5)
Elapsed time is 6.444622 seconds.
ans =
0.577215664902138
So, after 6.4 seconds and 1 billion terms, I was pretty close. You won't be able to get 50 decimal digits that way though. It as been a while, but in the documentation for eulerGamma in my HPF tool, I had these comments:
% Uses the Bessel function method from:
% http://numbers.computation.free.fr/Constants/Gamma/gamma.pdf
%
% See also:
% http://en.wikipedia.org/wiki/Euler?Mascheroni_constant

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by