利息计算的理论和代码实现。
import org.apache.commons.math3.analysis.solvers.BrentSolver;
public class InterestCalc {
public static void main(String[] args) {
BrentSolver solver = new BrentSolver(1E-14);
double rate = solver.solve(1000, r -> {
double powBase = 1 + r;
return -1000 + 300 * (Math.pow(powBase, -2) + Math.pow(powBase, -3) + Math.pow(powBase, -4)) + 200 * Math.pow(powBase, -5);}, -1, 1, 0);
System.out.println(rate); // 0.028881921824791823
}
}