# How to obtain integral in Mathematica faster? (Using parallel table?)

Hello Wolfram killers,

Sasha was near, but how to obtain these two integrals? Ok 500 is to much for calculating, but 200, ok?

f[r_] := Sum[(((-1)^n*(2*r - 2*n - 7)!!)/(2^n*n!*(r - 2*n - 1)!))*
x^(r - 2*n - 1), {n, 0, r/2}];

Nw := Transpose[Table[f[j], {i, 1}, {j, 5, 500, 1}]];

X1 = Integrate[Nw . Transpose[Nw], {x, -1, 1}];

Y1 = Integrate[D[Nw, {x, 2}] . Transpose[D[Nw, {x, 2}]], {x, -1, 1}];

MatrixForm[X1]

MatrixForm[Y1]

-
I don't know why you don't simply mark your code but it would be great if you can just click the code button when you are entering your Mathematica code. See the question edit for the difference. – user13838 Nov 4 '11 at 9:36

There is no need for it. Firstly,

f[r_] = FullSimplify[
Sum[(((-1)^n*(2*r - 2*n - 7)!!)/(2^n*n!*(r - 2*n - 1)!))*
x^(r - 2*n - 1), {n, 0, r/2}], r > 0 && r \[Element] Integers]


simplifies to $$f(r)=-\frac{\sqrt{\pi } (-1)^r 2^{r-3} x^{r-1} \, _2\tilde{F}_1\left(\frac{1-r}{2},1-\frac{r}{2};\frac{7}{2}-r;\frac{1}{x^2}\right)}{\Gamma (r)}.$$ Caculations show that only a few diagonals have non-zero elements: $$\tiny \left( \begin{array}{ccccccccccc} \frac{4}{315} & 0 & -\frac{8}{10395} & 0 & \frac{2}{45045} & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & \frac{4}{3465} & 0 & -\frac{8}{45045} & 0 & \frac{2}{135135} & 0 & 0 & 0 & 0 & 0 \\ -\frac{8}{10395} & 0 & \frac{4}{15015} & 0 & -\frac{8}{135135} & 0 & \frac{2}{328185} & 0 & 0 & 0 & 0 \\ 0 & -\frac{8}{45045} & 0 & \frac{4}{45045} & 0 & -\frac{8}{328185} & 0 & \frac{2}{692835} & 0 & 0 & 0 \\ \frac{2}{45045} & 0 & -\frac{8}{135135} & 0 & \frac{4}{109395} & 0 & -\frac{8}{692835} & 0 & \frac{2}{1322685} & 0 & 0 \\ 0 & \frac{2}{135135} & 0 & -\frac{8}{328185} & 0 & \frac{4}{230945} & 0 & -\frac{8}{1322685} & 0 & \frac{2}{2340135} & 0 \\ 0 & 0 & \frac{2}{328185} & 0 & -\frac{8}{692835} & 0 & \frac{4}{440895} & 0 & -\frac{8}{2340135} & 0 & \frac{2}{3900225} \\ 0 & 0 & 0 & \frac{2}{692835} & 0 & -\frac{8}{1322685} & 0 & \frac{4}{780045} & 0 & -\frac{8}{3900225} & 0 \\ 0 & 0 & 0 & 0 & \frac{2}{1322685} & 0 & -\frac{8}{2340135} & 0 & \frac{4}{1300075} & 0 & -\frac{8}{6194475} \\ 0 & 0 & 0 & 0 & 0 & \frac{2}{2340135} & 0 & -\frac{8}{3900225} & 0 & \frac{4}{2064825} & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & \frac{2}{3900225} & 0 & -\frac{8}{6194475} & 0 & \frac{4}{3151575} \end{array} \right),$$ $$\left( \begin{array}{ccccccccccc} \frac{2}{5} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & \frac{2}{7} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & \frac{2}{9} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & \frac{2}{11} & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & \frac{2}{13} & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & \frac{2}{15} & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & \frac{2}{17} & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & \frac{2}{19} & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \frac{2}{21} & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \frac{2}{23} & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \frac{2}{25}. \end{array} \right)$$ And those diagonals satisfy simple formulas:

FindSequenceFunction[Diagonal[Y1], n] // Simplify
FindSequenceFunction[Diagonal[X1, 0], n] // Simplify
FindSequenceFunction[Diagonal[X1, 2], n] // Simplify
FindSequenceFunction[Diagonal[X1, 4], n] // Simplify


gives $$\frac{2}{2 n+3}\ ,$$ $$\frac{12}{32 n^5+240 n^4+560 n^3+360 n^2-142 n-105}\ ,$$ $$-\frac{8}{32 n^5+400 n^4+1840 n^3+3800 n^2+3378 n+945}\ ,$$ $$\frac{2}{32 n^5+560 n^4+3760 n^3+12040 n^2+18258 n+10395}\ .$$

-
But how to obtain now X1 and Y1 for example order 20? I must define X1 and Y1 in function of n? How? – George Nov 4 '11 at 9:42
@George be direct calculations in mathematica. With the indicated above simplification of $f(r)$ and ParallelTable[]: Nw := Transpose[ParallelTable[f[j], {i, 1}, {j, 5, 20, 1}]]; etc. – Andrew Nov 4 '11 at 10:08
Dear Andrew, with this transformation, also the time of computing is almost the same. Maybe it is better solution to FindSequenceFunction[Diagonal[Y1], n] for 200x200 matrix and then make a rule for matrix in function of n? For example: n = 7; MatrixForm[ DiagonalMatrix[Array[Subscript[a, #] &, n - 2], -2] + DiagonalMatrix[Array[Subscript[b, #] &, n]] + DiagonalMatrix[Array[Subscript[c, #] &, n - 2], 2]] But how to define a,b,c from already finished rule of n? – George Nov 4 '11 at 11:27
What do you think about this n = 12; X1 = MatrixForm[DiagonalMatrix[ Array[2/( 10395 + 18258 # + 12040 #^2 + 3760 #^3 + 560 #^4 + 32 #^5)&,n-4],-4]+DiagonalMatrix[Array[-(8/(945 + 3378 # +3800 #^2 + 1840 #^3 + 400 #^4 + 32 #^5)) &, n-2],-2] + DiagonalMatrix[Array[12/(-105 - 142 # + 360 #^2 + 560 #^3 + 240 #^4 + 32 #^5) &,n]] + DiagonalMatrix[Array[-(8/( 945 + 3378 # + 3800 #^2 + 1840 #^3 + 400 #^4 + 32 #^5)) &,n - 2], 2] +DiagonalMatrix[Array[2/(10395 + 18258 # + 12040 #^2 + 3760 #^3 + 560 #^4 + 32 #^5)&,n - 4], 4]]; Y1=MatrixForm[DiagonalMatrix[Array[2/(3 + 2 #) &, n]]]; X1 Y1 – George Nov 4 '11 at 12:29
@George may be I'm missing something but it works fine on mine computer. AbsoluteTiming[ Nw := Transpose[ParallelTable[f[j], {i, 1}, {j, 5, 20, 1}]]; X1 = Integrate[Nw.Transpose[Nw], {x, -1, 1}]; Y1 = Integrate[D[Nw, {x, 2}].Transpose[D[Nw, {x, 2}]], {x, -1, 1}]; Rationalize[MatrixForm[X1]] Rationalize[MatrixForm[Y1]] ]' gives 12 seconds. Thean I proceed as above. The case of 200x200 isn't calculated. The answer seems to be the same for all $r$. – Andrew Nov 4 '11 at 12:36