Thursday, March 5, 2015

Root approximation methods in Java

RootApproximations.java
This is a class containing implementations of known numerical analysis algorithms for root approximation. The error margin can be specified and has a default value of 5e-7.The function is represented with a class implementing a specific interface and must contain a method for f(x) and f'(x). Check github for examples.

Algorithms:

Root.java
A simple Java class to easily save the value and the loops required to reach root approximations.

public class Root {
    private final double value;
    private final int loops;

    public Root() {
        value = Double.NaN;
        loops = -1;
    }

    public Root(double v, int l) {
        value = v;
        loops = l;
    }

    public double getValue() {
        return value;
    }

    public int getLoops() {
        return loops;
    }
}

No comments: