public Algebraic integrate(Variable var) throws JasymcaException { Algebraic in = Zahl.ZERO; for (int i = 1; i < coef.length; i++) { if (!coef[i].depends(var)) if (var.equals(this.var)) // c*x^n -->1/(n+1)*x^(n+1) in = in.add(coef[i].mult(new Polynomial(var).pow_n(i + 1).div(new Unexakt(i + 1)))); else if (this.var instanceof FunctionVariable && ((FunctionVariable) this.var).arg.depends(var)) // f(x) if (i == 1) in = in.add(((FunctionVariable) this.var).integrate(var).mult(coef[1])); // (f(x))^2, (f(x))^3 etc // give up here but try again after exponential normalization else throw new JasymcaException("Integral not supported."); else // Constant: c --> c*x in = in.add(coef[i].mult(new Polynomial(var).mult(new Polynomial(this.var).pow_n(i)))); else if (var.equals(this.var)) // c(x)*x^n , should not happen if this is canonical throw new JasymcaException("Integral not supported."); else if (this.var instanceof FunctionVariable && ((FunctionVariable) this.var).arg.depends(var)) { if (i == 1 && coef[i] instanceof Polynomial && ((Polynomial) coef[i]).var.equals(var)) { // poly(x)*f(x) // First attempt: try to isolate inner derivative // poly(x)*f(w(x)) --> check poly(x)/w' == q : const? // yes --> Int f dw * q p("Trying to isolate inner derivative " + this); try { FunctionVariable f = (FunctionVariable) this.var; Algebraic w = f.arg; // Innere Funktion Algebraic q = coef[i].div(w.deriv(var)); if (q.deriv(var).equals(Zahl.ZERO)) { // q - constant SimpleVariable v = new SimpleVariable("v"); Algebraic p = FunctionVariable.create(f.fname, new Polynomial(v)); Algebraic r = p.integrate(v).value(v, w).mult(q); in = in.add(r); continue; } } catch (JasymcaException je) { // Didn't work, try more methods } p("Failed."); // Some partial integrations follow. To // avoid endless loops, we flag this section // Coefficients of coef[i] must not depend on var for (int k = 0; k < ((Polynomial) coef[i]).coef.length; k++) if (((Polynomial) coef[i]).coef[k].depends(var)) throw new JasymcaException("Function not supported by this method"); if (loopPartial) { loopPartial = false; p("Partial Integration Loop detected."); throw new JasymcaException("Partial Integration Loop: " + this); } // First attempt: x^n*f(x) , n-times diff! // works for exp,sin,cos p("Trying partial integration: x^n*f(x) , n-times diff " + this); try { loopPartial = true; Algebraic p = coef[i]; Algebraic f = ((FunctionVariable) this.var).integrate(var); Algebraic r = f.mult(p); while (!(p = p.deriv(var)).equals(Zahl.ZERO)) { f = f.integrate(var).mult(Zahl.MINUS); r = r.add(f.mult(p)); } loopPartial = false; in = in.add(r); continue; } catch (JasymcaException je) { loopPartial = false; } p("Failed."); // Second attempt: x^n*f(x) , 1-times int! // works for log, atan p("Trying partial integration: x^n*f(x) , 1-times int " + this); try { loopPartial = true; Algebraic p = coef[i].integrate(var); Algebraic f = new Polynomial((FunctionVariable) this.var); Algebraic r = p.mult(f).sub(p.mult(f.deriv(var)).integrate(var)); loopPartial = false; in = in.add(r); continue; } catch (JasymcaException je3) { loopPartial = false; } p("Failed"); // Add more attempts.... throw new JasymcaException("Function not supported by this method"); } else throw new JasymcaException("Integral not supported."); } else // mainvar independend of var, treat as constant and integrate coef in = in.add(coef[i].integrate(var).mult(new Polynomial(this.var).pow_n(i))); } if (coef.length > 0) in = in.add(coef[0].integrate(var)); return in; }