private static void test() { Poly2 poly = new Poly2( new Complex(2, 3), new Complex(1, -2), new Complex(-1, 4)); poly.solve(); poly.print(); }
//Neumark - Solution Of Cubic & Quartic Equations public void solve() { x = new Complex[4]; if (B.abs() < 1e-12 && D.abs() < 1e-12) { Poly2 poly2 = new Poly2(A, C, E); poly2.solve(); x[0] = poly2.x[0].sqrt(); x[1] = x[0].negate(); x[2] = poly2.x[1].sqrt(); x[3] = x[2].negate(); } else { Poly3 subpoly = new Poly3(Complex.ONE, C * (-2), C * C + B * D - A * E * 4, -(B * C * D - B * B * E - A * D * D)); subpoly.solve(); Complex y = findMaxDelta(subpoly.x); Complex DeltaRoot = (B * B - A * y * 4).sqrt(); Complex G, g, H, h; if (DeltaRoot.abs() < 1e-12) { G = B * 0.5; g = G; H = (C - y) * 0.5; h = H; } else { G = (B + DeltaRoot) * 0.5; g = (B - DeltaRoot) * 0.5; Complex part = (B * (C - y) - A * D * 2) / (DeltaRoot * 2); H = (C - y) * 0.5 + part; h = (C - y) * 0.5 - part; } Poly2 poly2a = new Poly2(A, G, H); poly2a.solve(); Poly2 poly2b = new Poly2(A, g, h); poly2b.solve(); x[0] = poly2a.x[0]; x[1] = poly2a.x[1]; x[2] = poly2b.x[0]; x[3] = poly2b.x[1]; } }