2
$\begingroup$

I use of Distribute for multiply a parameter in Integral. I write the following code:

Distribute[
 p*Integrate[(u[0][x] + p*u[1][x] + p^2*u[2][x])/Sqrt[t - x], {x, 0, 
    t}]]

I want the following output:

Integrate[(p*u[0][x])/Sqrt[t - x], {x, 0, t}] + 
 Integrate[(p^2*u[1][x])/Sqrt[t - x], {x, 0, t}] + 
     Integrate[Plus[(p^3*u[2][x])/Sqrt[t - x]], {x, 0, t}]

Any suggestion?

$\endgroup$

1 Answer 1

2
$\begingroup$
exp = p Integrate[(u[0][x] + p u[1][x] + p^2 u[2][x]) / Sqrt[t - x], {x, 0, t}]; 

ExpandAll[exp] /.  a_ Integrate[b_, c_] :> (Integrate[a #, c] & /@ b)

enter image description here

To have the p's outside Integrates:

ExpandAll[exp] /.  p Integrate[b_,  c_] :>
  ((p Replace[#, Except[p^_.] :> 1, Infinity] Integrate[  # /. p -> 1, c]) & /@ b)

enter image description here

$\endgroup$
2
  • $\begingroup$ Many thanks. Is there any war for the following output: p*Integrate[u[0][x]/Sqrt[t - x], {x, 0, t}] + p^2*Integrate[u[1][x]/Sqrt[t - x], {x, 0, t}] + p^3*Integrate[u[2][x]/Sqrt[t - x], {x, 0, t}] $\endgroup$
    – Abdol Ali
    Mar 16, 2018 at 7:50
  • $\begingroup$ @AbdolAli, maybe ExpandAll[exp] /. p Integrate[b_, c_] :> (( p Replace[#, Except[p^_.] :> 1, Infinity] Integrate[ # /. p -> 1, c]) & /@ b) ? $\endgroup$
    – kglr
    Mar 16, 2018 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.