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 =
Array[Integrate[
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.
CosInt * BoxMatrix[0, 6] // MatrixForm
$\endgroup$Produce[[1,1]]
andProduce[[1,2]]
intoCosInt
,CosInt
can not understand thatProduce[[1,1]] and Produce[[1,1]]
are also functions ofi and j
. In spite of using strategies to avoid infinite expression encountering, it ignoreWhich
loop and just uses theProduce[[1,1]]
. I can not understand why this is happening !! $\endgroup$