Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save liewsi/5116824 to your computer and use it in GitHub Desktop.
Save liewsi/5116824 to your computer and use it in GitHub Desktop.
log_factorial_by_stirling_approximation = @(n)(log(2*pi*n)/2 + n.*log(n) - n);
n = 1:250;
y1 = log(factorial(n));
y2 = log_factorial_by_stirling_approximation(n);
subplot(3,1,1),
plot(n,y1, 'k-'), axis([0 max(n) 0 max(y2)]),
title('MATLAB faktöryelinin logu')
subplot(3,1,2),
plot(n,y2, 'b-'), axis([0 max(n) 0 max(y2)]),
title('Stirling yaklaşımının logu')
subplot(3,1,3),
plot(n,abs(y1-y2), 'r-'), title('Fark')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment