本文整理汇总了Java中org.apache.commons.math3.exception.util.LocalizedFormats.POLYNOMIAL属性的典型用法代码示例。如果您正苦于以下问题:Java LocalizedFormats.POLYNOMIAL属性的具体用法?Java LocalizedFormats.POLYNOMIAL怎么用?Java LocalizedFormats.POLYNOMIAL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.math3.exception.util.LocalizedFormats
的用法示例。
在下文中一共展示了LocalizedFormats.POLYNOMIAL属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: solveAll
/**
* Find all complex roots for the polynomial with the given
* coefficients, starting from the given initial value.
*
* @param coefficients Polynomial coefficients.
* @param initial Start value.
* @return the point at which the function value is zero.
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException
* if the maximum number of evaluations is exceeded.
* @throws NullArgumentException if the {@code coefficients} is
* {@code null}.
* @throws NoDataException if the {@code coefficients} array is empty.
*/
public Complex[] solveAll(Complex coefficients[], Complex initial)
throws NullArgumentException,
NoDataException,
TooManyEvaluationsException {
if (coefficients == null) {
throw new NullArgumentException();
}
final int n = coefficients.length - 1;
if (n == 0) {
throw new NoDataException(LocalizedFormats.POLYNOMIAL);
}
// Coefficients for deflated polynomial.
final Complex c[] = new Complex[n + 1];
for (int i = 0; i <= n; i++) {
c[i] = coefficients[i];
}
// Solve individual roots successively.
final Complex root[] = new Complex[n];
for (int i = 0; i < n; i++) {
final Complex subarray[] = new Complex[n - i + 1];
System.arraycopy(c, 0, subarray, 0, subarray.length);
root[i] = solve(subarray, initial);
// Polynomial deflation using synthetic division.
Complex newc = c[n - i];
Complex oldc = null;
for (int j = n - i - 1; j >= 0; j--) {
oldc = c[j];
c[j] = newc;
newc = oldc.add(newc.multiply(root[i]));
}
}
return root;
}