Example 1: Zeros of a Polynomial
The zeros of a polynomial with real coefficients are computed.
import com.imsl.math.*;
public class ZeroPolynomialEx1 {
public static void main(String args[]) throws
ZeroPolynomial.DidNotConvergeException {
double coef[] = {-2, 4, -3, 1};
ZeroPolynomial zp = new ZeroPolynomial();
Complex root[] = zp.computeRoots(coef);
for (int k = 0; k < root.length; k++) {
System.out.println("root = " + root[k]);
System.out.println(" radius = "+ zp.getRadius(k));
System.out.println(" status = "+ zp.getStatus(k));
}
}
}
Output
root = 0.9999999999999999-0.9999999999999997i
radius = 1.9197212602501468E-14
status = false
root = 1.0000000000000004+1.0000000000000002i
radius = 1.9618522761623435E-14
status = false
root = 1.0000000000000002-3.3087224502121107E-24i
radius = 2.5512925105887074E-14
status = false
Link to Java source.