In the following program, the fec[x] is a function depending on $x$ while q3[t] and q5[t] are functions depending on $t$. Now, I want to use Integrate for the polynomial which is composed by fec[x], q3[t], q5[t], et al. for the independent variable $x$. I believe the result c is zero, but I don' t know why the software could not convert it to zero automatically. Could you help me?

inta = Cos[q3[t]] fec[x] q5[t]^2 D[q3[t], t]^2;
a = Integrate[inta, {x, 0, L1}];

b1 = Cos[q3[t]] q5[t]^2 D[q3[t], t]^2;
b = Integrate[fec[x], {x, 0, L1}] b1;

c = a - b;
  • $\begingroup$ Welcome to Mathematica.SE, SunnySky! Let me remind you three things we usually do here: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the FAQs! 3) When you see good Q&A, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. ALSO, remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign` $\endgroup$ – Dr. belisarius Aug 24 '12 at 11:53

The problem can be distilled to a much simpler form to help illustrate what is going on. (whenever you find a problem, try to find the most simple form that shows the problem)

It has to do with definite vs. indefinite integration.

Clear[q, x, L1]
Integrate[q[x]*f[t], x]

Out[52]= f[t]*Integrate[q[x], x]

You see that now it pulled the function that does not depend on the integration variable out.

Do the same, now using definite integration

Clear[q, x, L1]
Integrate[q[x]*f[t], {x, 0, L1}]

Out[54]= Integrate[f[t]*q[x], {x, 0, L1}]

You see, the f[t] remained inside. I am not a math guy, so can't explain why it does not remove f[t] out when it is a definite integration. But it looks like when it is definite integration, you need to tell it that those functions that explicitly depend on t and not x remain independent of x for the definite case. I do not know how to do this.

That is why this gives zero

Integrate[q[x]*f[t], x]-f[t]Integrate[q[x], x]
Out[55]= 0

while the definite version does not (which is what you are basically asking)

Integrate[q[x]*f[t], {x, 0, L1}] - f[t]*Integrate[q[x], {x, 0, L1}]
Out[56]= (-f[t])*Integrate[q[x], {x, 0, L1}] + Integrate[f[t]*q[x], {x, 0, L1}]

Just wanted to point the problem more clearly that is all.


Additional observation. It seems the simplification does not happen becuase Mathematica does not know that f[x] does not depend implicitly on t. See:


Out[14]= 0

Becuase it now sees that f[x] really does NOT really depend on t, then it pulled out g[t] and we get zero.

But when we write

 Clear[x, t, f, g, L1]
 Integrate[f[x]*g[t], {x, 0, L1}] - g[t]*Integrate[f[x], {x, 0, L1}]

 Out[17]= (-g[t])*Integrate[f[x], {x, 0, L1}] + Integrate[f[x]*g[t], {x, 0, L1}]

So, may be some assumptions is needed. Not sure now. Just thought to mention this.


You could use the trick @Jens showed here. See his post (and upvote it!) for an explanation:

fec /: Integrate[fec[x_], x_] := Intfec[x];
SetAttributes[Intfec, {NumericFunction}];

inta = Cos[q3[t]] fec[x] q5[t]^2 D[q3[t], t]^2;
a = Integrate[inta, {x, 0, L1}];

b1 = Cos[q3[t]] q5[t]^2 D[q3[t], t]^2;
b = Integrate[fec[x], {x, 0, L1}] b1;

a - b
-> 0
  • $\begingroup$ Dear Verde, Thanks for your help, and now my problem has been resolved. $\endgroup$ – SunnySky Aug 24 '12 at 6:34
  • $\begingroup$ I edited your answer to add a fix for version 10 that I also used in the answer you linked to. $\endgroup$ – Jens Aug 29 '14 at 17:24
  • $\begingroup$ @Jens Thanks! No v10 here yet, unable to test :( $\endgroup$ – Dr. belisarius Aug 29 '14 at 18:41

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.