Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GaussLegendre {
- public static void main(String[] args) {
- double x1 = Double.MAX_VALUE;
- for (double a0 = 1,
- b0 = 1 / Math.sqrt(2),
- t0 = 1. / 4,
- p0 = 1,
- x0 = (a0 + b0) * (a0 + b0) / 4 / t0,
- a1,
- b1,
- t1,
- p1;
- Math.abs(x0 - x1) > Double.MIN_NORMAL;
- a1 = (a0 + b0) / 2, b1 = Math.sqrt(a0 * b0), t1 = t0 - p0 * (a0 - a1) * (a0 - a1),
- p1 = 2 * p0, a0 = a1, b0 = b1, t0 = t1, p0 = p1, x0 = x1,
- x1 = (a0 + b0) * (a0 + b0) / 4 / t0) {}
- System.out.println(x1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement