Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions maths/lanczos_approximation.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'dart:math';
Copy link
Member

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


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
Copy link
Member

Choose a reason for hiding this comment

The 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);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add main function with tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove EOF,

run dart format on this file.