-
-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue Closed #218 Create Lanczos_approximation #223
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'dart:math'; | ||
|
||
double gamma(double x) { | ||
const double pi = 3.141592653589793; | ||
if (x < 0.5) { | ||
return pi / (sin(pi * x) * gamma(1 - x)); | ||
} | ||
x -= 1; | ||
double a = 0.99999999999980993; | ||
const List<double> p = [ | ||
676.5203681218851, -1259.1392167224028, 771.32342877765313, | ||
-176.61502916214059, 12.507343278686905, -0.13857109526572012, | ||
9.9843695780195716e-6, 1.5056327351493116e-7 | ||
Comment on lines
+10
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use descriptive variable names |
||
]; | ||
for (int i = 0; i < p.length; i++) { | ||
a += p[i] / (x + i + 1); | ||
} | ||
double t = x + p.length - 0.5; | ||
return sqrt(2 * pi) * pow(t, x + 0.5) * exp(-t) * a; | ||
} | ||
|
||
double factorial(num n) { | ||
if (n is int) { | ||
assert(n >= 0, "Factorial of a negative number does not exist"); | ||
} | ||
return gamma(n + 1); | ||
} | ||
|
||
double signedFactorial(int n) { | ||
if (n % 2 == 0) { | ||
return factorial(n); | ||
} else { | ||
return -factorial(n); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add main function with tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove EOF, run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add url to lanczos approximation