# How to obtain big matrix in Mathematica?

Can you help me how to obtain big but simple matrix in Mathematica?

f[r_] := Sum[((2*r - 2*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}]];
X = Integrate[Nw . Transpose[Nw], {x, -1, 2}];
MatrixForm[X]


Regards!

-
"big but simple" - I don't follow. What were you expecting to see here? – J. M. Oct 31 '11 at 16:50
Can you explain what the problem is? – Phira Oct 31 '11 at 17:35

If you massage your problem a little it becomes easier for Mathematica.

$f_r(x) = \sum_{n=0}^{\lfloor \frac{r-1}{2} \rfloor}c_{r,n} x^{r-2n-1} = \sum_{n=0}^{\lfloor \frac{r-1}{2} \rfloor} \frac{ (2 r - 2 n)!!}{(r- 2n-1)!} x^{r-2n-1}$.

The matrix element $X_{pq} = \int_{-1}^2 f_p(x) f_q(x) \mathrm{d} x = \sum_{n=0}^{\lfloor \frac{p-1}{2} \rfloor} \sum_{m=0}^{\lfloor \frac{q-1}{2} \rfloor} c_{p,n} c_{q,m} \int_{-1}^2 x^{p+q -2(n+m+1)} \mathrm{d} x$. After carrying out trivial integration, this becomes: $$X_{pq} = \sum_{n=0}^{\lfloor \frac{p-1}{2} \rfloor} \sum_{m=0}^{\lfloor \frac{q-1}{2} \rfloor} c_{p,n} c_{q,m} \frac{2^{p+q -2(n+m) -1} + (-1)^{p+q}}{p+q -2(n+m) -1}$$

The code that would do this is as follows:

c[r_, n_] := ((2*r - 2*n)!!/(r - 2*n - 1)!);
X2 = Table[
Sum[c[p, n] c[q, m] (2^(p + q - 2 (n + m) - 1) + (-1)^(p + q))/(
p + q - 2 (n + m) - 1), {n, 0, Floor[(p - 1)/2]}, {m, 0,
Floor[(q - 1)/2]}], {p, 5, 500}, {q, 5, 500}]


Some words of caution: The generation is slow. Generating matrix with ranges {p,5,100}, {q,5,100} takes over 4 minutes on my machine. The matrix $X$ is manifestly symmetric, which would lead to a speed-up, reducing the run-time to about 90 seconds:

Xmat[{imin_, imax_}] := Module[{mat},
Table[Sum[(2^(-n + p) Gamma[1 - n + p])/Gamma[-2 n + p] (
2^(-m + q) Gamma[1 - m + q])/
Gamma[-2 m + q] ((2)^(p + q - 2 (n + m) - 1) + (-1)^(p + q))/(
p + q - 2 (n + m) - 1), {n, 0, Floor[(p - 1)/2]}, {m, 0,
Floor[(q - 1)/2]}], {p, imin, imax}, {q, imin, p}]];
mat + Transpose[LowerTriangularize[mat, -1]]
]

-
@George Yes, of course. It is rather straightforward. In the approach I took, you should redefine $c_{r,n}$ and replace the result of integration from $-1..2$ with the one from $-1..1$. – Sasha Oct 31 '11 at 18:27
yes, yes. Thank you very much Sasha! – George Oct 31 '11 at 19:24
Is it possible to use all cores for computing, I mean parallelize command for this kind of calculation? – George Oct 31 '11 at 20:04
@George Yes, of course. All you need is to replace Table with ParallelTable. – Sasha Oct 31 '11 at 20:18
Y2=Integrate[D[Nw, {x, 2}].Transpose[D[Nw, {x, 2}]], {x, -1, 1}]? I got from integral Integrate[D[x^(p+q-2*(m + n + 1)), {x, 2}], {x, -1, 1}] solution (-1 - 2*(1+m+n) +p +q)*(-2*(1+m+n) + p + q)*(-((-1)^(-2*m-2*n+p+q)/(3 + 2*m + 2*n - p-q)) + 1/(-3 - 2*m - 2*n + p + q)) and then try c[r_, n_] := ((-1)^n*(2*r - 2*n - 7)!!)/(2^n*n!*(r - 2*n - 1)!); Y2 = Table[ Sum[c[p, n]*c[q, m]*((-1 - 2*(1 + m + n) + p + q)*(-2*(1 + m + n) + p + q)*(-((-1)^(-2*m - 2*n + p + q)/(3 + 2*m + 2*n - p - q)) + 1/(-3 - 2*m - 2*n + p + q))),{n, 0, Floor[(p - 1)/2]},{m, 0, Floor[(q - 1)/2]}], {p, 5,12}, {q, 5, 12}] – George Nov 1 '11 at 10:18