Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Following code (function) makes integrals and then replace f[x] with Cos functions and calculate the definite parametric integrals as it is shown below :

DoGenerateIntegrals[Number_] :=

Block[{GeneratingIntegrals, COS, LimitCOS},

GeneratingIntegrals = 
   Symbol["f"][x], {x, Symbol["x" <> ToString[2 # - 1]], 
    Symbol["x" <> ToString[2 #]]}] &, Number];

COS = Total[
 GeneratingIntegrals /. 
  f[x] -> Cos[((i \[Pi])/L) x] Cos[((j \[Pi])/L) x]];
LimitCOS = Limit[COS, i -> j];

{COS, LimitCOS}];

Then :

In[1]:= Produce = DoGenerateIntegrals[2]

By using the results of the In[1] :

CosInt = Which[i != j, Produce[[1, 1]], i == j, Produce[[1, 2]]];

Which CosInt is to avoid encountering Infinite expression (1/0).

Now it will use in a code like below in a matrix :

List1 = Table[0, {i, 1, 6}, {j, 1, 6}];

Do[Do[List1[[i + 2, j + 2]] = CosInt, {j, 1, 2}], {i, 1, 2}];

List1 // MatrixForm

In DoGenerateIntegrals[] when the integrals evaluates with mentioned f[x], there will i-j in their denominator of their fractions which cause Infinite expression in List1 calculation. In order to avoid encountering Infinite expression (1/0), I use LimitCOS and CosInt to calculate the circumstances of i=j . But after calculation, it will face encountering Infinite expression (1/0) with following error:

Power::infy: Infinite expression 1/0 encountered.>>
Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered.>>

I wonder why this is happening; however, I have used some strategies to avoid it.

share|improve this question
Also, FYI: CosInt * BoxMatrix[0, 6] // MatrixForm –  Mr.Wizard Apr 16 at 22:04
@Mr.Wizard : I think the problem is not about "Indeterminate expression",the major problem about above code is that when I put Produce[[1,1]] and Produce[[1,2]] into CosInt, CosInt can not understand that Produce[[1,1]] and Produce[[1,1]] are also functions of i and j. In spite of using strategies to avoid infinite expression encountering, it ignore Which loop and just uses the Produce[[1,1]]. I can not understand why this is happening !! –  Shellp Apr 17 at 6:44
I wish to help, but I would like to address your questions in the order they appeared. Will you please reply to my requests in my answer to A problem with set values first? –  Mr.Wizard Apr 17 at 6:57
This question appears to be off-topic because it is too localized. –  Oleksandr R. May 11 at 3:04

Your Answer


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

Browse other questions tagged or ask your own question.