我想用Java计算极限(微积分)。我有以下类Limit
可以计算范围:微积分极限与Java
package calculus;
public final class Limit {
private Limit() {
}
public static final double limit(Function function, double approach) {
double below = Limit.limitFromBelow(function, approach);
double above = Limit.limitFromAbove(function, approach);
return below == above ? below : Double.NaN;
}
public static final double limitFromBelow(Function function, double approach) {
for (double d = approach - 10; d <= approach; d = approach
- ((approach - d)/10)) {
if (function.apply(d) == Double.POSITIVE_INFINITY) {
return Double.POSITIVE_INFINITY;
} else if (function.apply(d) == Double.NEGATIVE_INFINITY) {
return Double.NEGATIVE_INFINITY;
} else if (Double.isNaN(function.apply(d))) {
return function.apply(approach + ((approach - d) * 10));
} else {
if (d == approach) {
return function.apply(d);
} else if (approach - d < 0.00000000001) {
d = approach;
}
}
}
return Double.NaN;
}
public static final double limitFromAbove(Function function, double approach) {
for (double d = approach + 10; d >= approach; d = approach
- ((approach - d)/10)) {
if (function.apply(d) == Double.POSITIVE_INFINITY) {
return Double.POSITIVE_INFINITY;
} else if (function.apply(d) == Double.NEGATIVE_INFINITY) {
return Double.NEGATIVE_INFINITY;
} else if (Double.isNaN(function.apply(d))) {
return function.apply(approach + ((approach - d) * 10));
} else {
if (d == approach) {
return function.apply(d);
} else if (d - approach < 0.00000000001) {
d = approach;
}
}
}
return Double.NaN;
}
}
不过,我想知道:是否有另一种方法来计算比疲惫和递归测试其他限制?有没有更有效的方法?
如果我是你,我会研究L'Hopital的评估限制规则。它可能非常有帮助,尽管你可能需要在'Function'类中添加一些方法。 (如下所示:http://tutorial.math.lamar.edu/Classes/CalcI/LHospitalsRule.aspx) – StephenButtolph