Skip to content

Instantly share code, notes, and snippets.

@Altanis
Created June 29, 2022 00:03
Show Gist options
  • Save Altanis/66b1ab5e837810fb801495f17c8ceb06 to your computer and use it in GitHub Desktop.
Save Altanis/66b1ab5e837810fb801495f17c8ceb06 to your computer and use it in GitHub Desktop.
Computing the nth Degree of a Taylor Polynomial
class Main {
private static double factorial(int n) {
double result = 1;
for (int i = 1; i <= n; i++) {
result *= i;
}
return result;
}
public static double taylorE(double x, int n) {
double result = 0.0;
for (int i = 0; i < n; i++) {
double numerator = Math.pow(x, i);
double denominator = factorial(i);
result += numerator / denominator;
}
return result;
}
public static void main(String[] args) {
System.out.println(taylorE(1, 10));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment