0
$\begingroup$

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!

  • 0
    "big but simple" - I don't follow. What were you expecting to see here?2011-10-31
  • 0
    Can you explain what the problem is?2011-10-31

1 Answers 1

2

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},
  mat = PadRight[
    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]]
  ]
  • 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$.2011-10-31
  • 0
    yes, yes. Thank you very much Sasha!2011-10-31
  • 0
    Is it possible to use all cores for computing, I mean parallelize command for this kind of calculation?2011-10-31
  • 1
    @George Yes, of course. All you need is to replace `Table` with `ParallelTable`.2011-10-31
  • 0
    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}]2011-11-01
  • 0
    The problem starting with this case! Y2=Integrate[D[Nw, {x, 2}].Transpose[D[Nw, {x, 2}]], {x, -1, 1}]2011-11-01
  • 0
    You or me got the wrong integral: FullSimplify[Integrate[x^(p + q - 2*(m + n + 1)), {x, -1, 2}]] solution ConditionalExpression[-((2*(-1)^(-2*m - 2*n + p + q) + 2^(-2*m - 2*n + p + q))/(2*(1 + 2*m + 2*n - p - q))), Re[-2*m - 2*n + p + q] > 1]2011-11-03
  • 0
    This expression and mine are the same if $m$ and $n$ are integers, which they are. Remember that $(-1)^{2m} = 1$ for integer $m$.2011-11-03
  • 0
    Yes but it is not working, take a look here http://math.stackexchange.com/questions/78996/how-to-solve-integral-in-mathematica2011-11-04