This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
NumericalAnalysisModule/1 - Numerical Series Approx.../source/java for speed comparison/Question3.java

29 lines
590 B
Java

public class Question3 {
public static void main(String[] args) {
double err = Math.pow(10, -Integer.parseInt(args[0].trim()));
compute_serie_2(err);
}
public static double compute_serie_3_term(long n)
{
return -((double)(2*n+1))/(double)(2*n+3);
}
public static void compute_serie_2(double err)
{
long k = 0;
double ak = 1;
double acc = 1;
while (err < 4 * Math.abs(ak)) {
ak = compute_serie_3_term(k++) * ak;
acc += ak;
}
System.out.println(k + " " + 4 * acc);
}
}