internal virtual Algebraic fzexakt(Zahl x) { if (x.smaller(Zahl.ZERO)) { Algebraic r = fzexakt((Zahl)x.mult(Zahl.MINUS)); if (r != null) { return(r.cc()); } return(r); } if (x.integerq()) { if (x.intval() % 2 == 0) { return(Zahl.ONE); } else { return(Zahl.MINUS); } } Algebraic qs = x.add(new Unexakt(.5)); if (((Zahl)qs).integerq()) { if (((Zahl)qs).intval() % 2 == 0) { return(Zahl.IMINUS); } else { return(Zahl.IONE); } } qs = x.mult(new Unexakt(4)); if (((Zahl)qs).integerq()) { Algebraic sq2 = FunctionVariable.create("sqrt", new Unexakt(0.5)); switch (((Zahl)qs).intval() % 8) { case 1: return(Zahl.ONE.add(Zahl.IONE).div(Zahl.SQRT2)); case 3: return(Zahl.MINUS.add(Zahl.IONE).div(Zahl.SQRT2)); case 5: return(Zahl.MINUS.add(Zahl.IMINUS).div(Zahl.SQRT2)); case 7: return(Zahl.ONE.add(Zahl.IMINUS).div(Zahl.SQRT2)); } } qs = x.mult(new Unexakt(6)); if (((Zahl)qs).integerq()) { switch (((Zahl)qs).intval() % 12) { case 1: return(Zahl.SQRT3.add(Zahl.IONE).div(Zahl.TWO)); case 2: return(Zahl.ONE.add(Zahl.SQRT3.mult(Zahl.IONE)).div(Zahl.TWO)); case 4: return(Zahl.SQRT3.mult(Zahl.IONE).add(Zahl.MINUS).div(Zahl.TWO)); case 5: return(Zahl.IONE.sub(Zahl.SQRT3).div(Zahl.TWO)); case 7: return(Zahl.IMINUS.sub(Zahl.SQRT3).div(Zahl.TWO)); case 8: return(Zahl.SQRT3.mult(Zahl.IMINUS).sub(Zahl.ONE).div(Zahl.TWO)); case 10: return(Zahl.SQRT3.mult(Zahl.IMINUS).add(Zahl.ONE).div(Zahl.TWO)); case 11: return(Zahl.IMINUS.add(Zahl.SQRT3).div(Zahl.TWO)); } } return(null); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public int lambda(Stack st) throws ParseException, JasymcaException public override int lambda(Stack st) { int narg = getNarg(st); if (narg != 4) { throw new ParseException("Usage: ROMBERG (exp,var,ll,ul)"); } Algebraic exp = getAlgebraic(st); Variable v = getVariable(st); Algebraic ll = getAlgebraic(st); Algebraic ul = getAlgebraic(st); LambdaAlgebraic xc = new ExpandConstants(); exp = xc.f_exakt(exp); ll = xc.f_exakt(ll); ul = xc.f_exakt(ul); if (!(ll is Zahl) || !(ul is Zahl)) { throw new ParseException("Usage: ROMBERG (exp,var,ll,ul)"); } double rombergtol = 1.0e-4; int rombergit = 11; Zahl a1 = pc.env.getnum("rombergit"); if (a1 != null) { rombergit = a1.intval(); } a1 = pc.env.getnum("rombergtol"); if (a1 != null) { rombergtol = a1.unexakt().real; } double a = ((Zahl)ll).unexakt().real; double b = ((Zahl)ul).unexakt().real; //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: double[][] I = new double[rombergit][rombergit]; double[][] I = RectangularArrays.ReturnRectangularDoubleArray(rombergit, rombergit); int i = 0, n = 1; Algebraic t = trapez(exp, v, n, a, b); if (!(t is Zahl)) { throw new ParseException("Expression must evaluate to number"); } I[0][0] = ((Zahl)t).unexakt().real; double epsa = 1.1 * rombergtol; while (epsa > rombergtol && i < rombergit - 1) { i++; n *= 2; t = trapez(exp, v, n, a, b); I[0][i] = ((Zahl)t).unexakt().real; double f = 1.0; for (int k = 1; k <= i; k++) { f *= 4; I[k][i] = I[k - 1][i] + (I[k - 1][i] - I[k - 1][i - 1]) / (f - 1.0); } epsa = Math.Abs((I[i][i] - I[i - 1][i - 1]) / I[i][i]); } st.Push(new Unexakt(I[i][i])); return(0); }