3

I am dealing with the symbolic operation of taking the antiderivative, e.g., Integrate[f, x] (where $f$ represents a complicated function which cannot return integral value directly)

I want to change the integral variable $x \mapsto x+a$,so I simply % /. x-> y + a. The result was that the form of integral seemly change to Integrate[f, y + a]

But this produces the error:

Invalid integration variable or limit(s) in y + a.

So I have two questions:

  1. How do I tell Mathematica to deal with the change of integral variable automatically? That is, how produce the change of $d(y + a)$ to $dy$.
  2. In a definite integral, is there some ways to change the integral upper and lower limits automatically in the same way as I want to change the integral variable?
m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Merlin Zhang
  • 155
  • 5

2 Answers2

2

A simple replacement of the variable won't do if you want to perform general integration by substitution. We can define a function like the following for this task:

intSub[x_ -> g_, y_][expr_] := 
 expr /. {Integrate[f_, x] :> Integrate[(f /. x -> g) D[g, y], y], 
   Integrate[f_, {x, a_, b_}] :> 
    Integrate[(f /. x -> g) D[g, y], 
     Prepend[y /. Solve[g == x, y][[1]] /. {{x -> a}, {x -> b}}, y]]}

Applications:

Integrate[f[x], x] // intSub[x -> y + a, y]

$\int f(a+y) \, dy$

Integrate[f[x], x] // intSub[x -> -y, y]

$-\int f(-y) \, dy$

Integrate[f[x], {x, a, b}] // intSub[x -> g[y], y]
Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.

$\int_{g^{(-1)}(a)}^{g^{(-1)}(b)} f(g(y)) g'(y) \, dy$

Note that the change of upper and lower limits only works as expected if Solve[g == x, y][[1]] works out the correct inverse of x = g(y).

1

If I understand the question correctly, the following should work. Beginning with

int = Integrate[f[x], {x, b, c}];

Then,

int /. {f[x] -> f[x - a], {x, b, c} -> {x, b + a, c + a}}
(* Integrate[f[-a + x], {x, a + b, a + c}]  *)

shifts x by a while leaving the value of the integral unchanged. For instance,

Integrate[Sin[x], {x, b, c}]
(* Cos[b] - Cos[c] *)

Unevaluated[Integrate[Sin[x], {x, b, c}]] /. {Sin[x] -> Sin[x - a], 
    {x, b, c} -> {x, b + a, c + a}}
(* Cos[b] - Cos[c] *)

as expected. (Unevaluated is used to prevent this simple integral from being evaluated before the change of argument and limits.) If changing the argument and limits independently is desired, then use something like

int /. {f[x] -> f[x - a], {x, b, c} -> {x, b + u, c + v}}

or whatever is desired.

bbgodfrey
  • 61,439
  • 17
  • 89
  • 156
  • But if the change of integral is more complex, e.g. $x \mapsto -x$, then it will return a negative sign after above operations. Do I have to multiple such coefficient manually? – Merlin Zhang Nov 01 '18 at 02:24
  • It depends on what you are trying to accomplish. – bbgodfrey Nov 01 '18 at 03:50