Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As shown in the following program, the q[t] in a can be collected from the integration by defining the integration of fe1[x] as Infe1[x], the same is true for fe2[x] in b. But for the equation c, how can I collect q[t] from it?

fe1 /: Integrate[fe1[x_], x_] := Infe1[x];
fe2 /: Integrate[fe2[x_], x_] := Infe2[x];

a = Integrate[fe1[x]*q[t], {x, 0, L1}]

b = Integrate[fe2[x]*q[t], {x, 0, L1}]   

c = Integrate[fe1[x]*fe2[x]*q[t], {x, 0, L1}]
share|improve this question
@SunnySky, if you want to convert typeset math (TraditionalForm) input into InputForm you can use Hold[ yourexpression ] // InputForm and copy and paste the bit inside Hold[]. – Verbeia Aug 29 '12 at 3:59

You could do it with a rule:

myrule = Integrate[Times[x_, q[t]], y_] :> q[t] Integrate[x, y]

c = Integrate[fe1[x]*fe2[x]*q[t], {x, 0, L1}] /. myrule

(*  ==>  Integrate[fe1[x]*fe2[x], {x, 0, L1}]*q[t]   *)


For more generality, you could do

myrule2 = Integrate[Times[x_, c_], {y_, y1_, y2_}] /; FreeQ[c, y] :> c  Integrate[x, {y, y1, y2}];

Integrate[(1 + Exp[h[t]]^2) g[x, t] f[x] Exp[q[t]], {x, 0, L1}] //. myrule2

(* ==> E^q[t]*(1 + E^(2*h[t])) * Integrate[f[x]*g[x, t], {x, 0, L1}] *)

Note the use of ReplaceRepeated (//.) rather than just ReplaceAll (/.).

share|improve this answer
your answer works well. thank you very much. Moreover, If the q[t] is substituted by q[t]*g[t]*r[t] or even a more complex functions that depend on "t", then how can I collect them from the integration without defining rules for each special functions? – SunnySky Aug 29 '12 at 7:12
@SunnySky please see if the update helps you – ecoxlinux Aug 29 '12 at 14:26
yes, your answer is very good. may be "//. myrule" should be replaced by "//. myrule2". Thank you very much. – SunnySky Aug 30 '12 at 1:57
Indeed. Corrected. – ecoxlinux Aug 30 '12 at 2:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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