Created
June 29, 2022 00:03
-
-
Save Altanis/66b1ab5e837810fb801495f17c8ceb06 to your computer and use it in GitHub Desktop.
Computing the nth Degree of a Taylor Polynomial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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