Integration of (a-b)^n



Thanks for your interest in Maxima!

For your simple indefinite integral, there is a simple solution.  Let me use
the conventional 'x' as the variable of integration just for clarity:

expr: integrate((x-a)^2,x);
  => x^3/3-a*x^2+a^2*x
expr1: polydecomp(expr,x);
  => [(x^3+a^3)/3,x-a]
compose (L, x) := block ([r : x], for e in L do r : subst (e, x, r), r) $
 /* see ? polydecomp ; this is its inverse */
expr2: compose(expr1,x);
  => ((x-a)^3+a^3)/3      <<< Here is your result, with the constant
multthru(expr1);
  => (x-a)^3/3+a^3/3    <<< pull out the constant into a separate term

I'm not quite sure what form you want to put integrate( (x-a)^n*sin(x), x)
in, but here are a couple of approaches (using n=3 for the example):

expr: integrate((x-a)^3*sin(x),x);
  =>
-3*a*(2*x*sin(x)+(2-x^2)*cos(x))+3*a^2*(sin(x)-x*cos(x))+(3*x^2-6)*sin(x)+(6*x-x^3)*cos(x)+a^3*cos(x)

----------------Approach 1---------------------
factorsum(expr);
  ==> 3*((x-a)^2-2)*sin(x)-(x-a)*((x-a)^2-6)*cos(x)

----------------Approach 2-------------------------------
subst(x-a,'xa,ratsubst('xa,x-a,expr));      <<< ratsubst does the heavy
lifting
  => (3*(x-a)^2-6)*sin(x)+(6*(x-a)-(x-a)^3)*cos(x)

-----------------Approach 3------------------------------
pullout(ex,q):=q*multthru(1/q,ex)$
substpart(pullout(piece,x-a),expr,2,1);   <<< pull out x-a from the 2nd term
  => (3*(x-a)^2-6)*sin(x)+(x-a)*(6-(x-a)^2)*cos(x)

-------------------Approach 4-------------------

factthru(a,b):=block([div: divide(a,b)], div[1]*b+div[2]);
factthru(expr,x-a);       <<< pull out x-a at the top level only
  =>
(x-a)*(x*(3*sin(x)+2*a*cos(x))-3*a*sin(x)-x^2*cos(x)-a^2*cos(x)+6*cos(x))-6*sin(x)
scanmap(lambda([q],factthru(q,x-a)),expr);    <<< recursively pull out x-a
  => (x-a)*((x-a)*(3*sin(x)-(x-a)*cos(x))+6*cos(x))-6*sin(x)
substpart(multthru(piece),%,1);    <<< expand out left term if desired
  => (x-a)^2*(3*sin(x)-(x-a)*cos(x))-6*sin(x)+6*(x-a)*cos(x)

Is any of that what you had in mind?

            -s

On Sun, Sep 19, 2010 at 12:50, Ian Bell <ibell at purdue.edu> wrote:

> Hello all,
>
> I'm a relatively new Maxima user, though I have found the software to be
> user friendly enough, and you can't beat the price.
>
> My question relates to definite integration, a tricky subject, and one
> which a lot of CAS programs struggle with.  So what I want to know is how I
> get
> integrate((a-b)^2,a) to give me the factored solution (a-b)^3/3 . Maxima
> (and Mathematica for that matter), expand the product and then group all the
> constants together since mathematically they all drop out when you plug in
> limits.  In this way it makes it impossible to refactor the anti-derivative
> back to the form (a-b)^3 .   I've got a lot of other integrals that I have a
> similar problem with, like (a-b)^n*sin(a) with n an integer.  For what its
> worth, in MATLAB (w/ MuPaD) int((a-b)^2,a) yields (a-b)^3/3
> Any thoughts would be greatly appreciated.
>
> Kind Regards,
> Ian
>
> ----
> Ian Bell
> Graduate Research Assistant
> Herrick Labs
> Purdue University
> email: ibell at purdue.edu
> cell: (607)227-7626
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>