public static Vector Horowitz(Algebraic p, Polynomial q, Variable x) { if (Poly.Degree(p, x) >= Poly.Degree(q, x)) { throw new SymbolicException("Degree of p must be smaller than degree of q"); } p = p.Rat(); q = ( Polynomial )q.Rat(); var d = Poly.poly_gcd(q, q.Derive(x)); var b = Poly.polydiv(q, d); var m = b is Polynomial ? (( Polynomial )b).Degree() : 0; var n = d is Polynomial ? (( Polynomial )d).Degree() : 0; var a = new SimpleVariable[m]; var X = new Polynomial(x); Algebraic A = Symbol.ZERO; for (var i = a.Length - 1; i >= 0; i--) { a[i] = new SimpleVariable("a" + i); A = A + new Polynomial(a[i]); if (i > 0) { A = A * X; } } var c = new SimpleVariable[n]; Algebraic C = Symbol.ZERO; for (var i = c.Length - 1; i >= 0; i--) { c[i] = new SimpleVariable("c" + i); C = C + new Polynomial(c[i]); if (i > 0) { C = C * X; } } var r = Poly.polydiv(C * b * d.Derive(x), d); r = b * C.Derive(x) - r + d * A; var aik = Matrix.CreateRectangularArray <Algebraic>(m + n, m + n); Algebraic cf; var co = new Algebraic[m + n]; for (var i = 0; i < m + n; i++) { co[i] = Poly.Coefficient(p, x, i); cf = Poly.Coefficient(r, x, i); for (var k = 0; k < m; k++) { aik[i][k] = cf.Derive(a[k]); } for (var k = 0; k < n; k++) { aik[i][k + m] = cf.Derive(c[k]); } } var s = LambdaLINSOLVE.Gauss(new Matrix(aik), new Vector(co)); A = Symbol.ZERO; for (var i = m - 1; i >= 0; i--) { A = A + s[i]; if (i > 0) { A = A * X; } } C = Symbol.ZERO; for (var i = n - 1; i >= 0; i--) { C = C + s[i + m]; if (i > 0) { C = C * X; } } return(new Vector(new[] { C / d, A / b })); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static Vektor horowitz(Algebraic p, Polynomial q, Variable x) throws JasymcaException public static Vektor horowitz(Algebraic p, Polynomial q, Variable x) { if (Poly.degree(p, x) >= Poly.degree(q, x)) { throw new JasymcaException("Degree of p must be smaller than degree of q"); } p = p.rat(); q = (Polynomial)q.rat(); Algebraic d = Poly.poly_gcd(q, q.deriv(x)); Algebraic b = Poly.polydiv(q, d); int m = b is Polynomial? ((Polynomial)b).degree():0; int n = d is Polynomial? ((Polynomial)d).degree():0; SimpleVariable[] a = new SimpleVariable[m]; Polynomial X = new Polynomial(x); Algebraic A = Zahl.ZERO; for (int i = a.Length - 1; i >= 0; i--) { a[i] = new SimpleVariable("a" + i); A = A.add(new Polynomial(a[i])); if (i > 0) { A = A.mult(X); } } SimpleVariable[] c = new SimpleVariable[n]; Algebraic C = Zahl.ZERO; for (int i = c.Length - 1; i >= 0; i--) { c[i] = new SimpleVariable("c" + i); C = C.add(new Polynomial(c[i])); if (i > 0) { C = C.mult(X); } } Algebraic r = Poly.polydiv(C.mult(b).mult(d.deriv(x)), d); r = b.mult(C.deriv(x)).sub(r).add(d.mult(A)); //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: Algebraic[][] aik = new Algebraic[m+n][m+n]; Algebraic[][] aik = RectangularArrays.ReturnRectangularAlgebraicArray(m + n, m + n); Algebraic cf; Algebraic[] co = new Algebraic[m + n]; for (int i = 0; i < m + n; i++) { co[i] = Poly.coefficient(p, x, i); cf = Poly.coefficient(r, x, i); for (int k = 0; k < m; k++) { aik[i][k] = cf.deriv(a[k]); } for (int k = 0; k < n; k++) { aik[i][k + m] = cf.deriv(c[k]); } } Vektor s = LambdaLINSOLVE.Gauss(new Matrix(aik), new Vektor(co)); A = Zahl.ZERO; for (int i = m - 1; i >= 0; i--) { A = A.add(s.get(i)); if (i > 0) { A = A.mult(X); } } C = Zahl.ZERO; for (int i = n - 1; i >= 0; i--) { C = C.add(s.get(i + m)); if (i > 0) { C = C.mult(X); } } co = new Algebraic[2]; co[0] = C.div(d); co[1] = A.div(b); return(new Vektor(co)); }