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.

I want to write a function $f[n]$ in Mathematica which gives me an $n\times n$ lower triangular Pascal matrix with a row of zeros in between each nonzero row. That is, I want the matrices \begin{pmatrix} 1&0&0\\ 0&0&0\\ 1&1&0\\ \end{pmatrix} \begin{pmatrix} 1&0&0&0&0\\ 0&0&0&0&0\\ 1&1&0&0&0\\ 0&0&0&0&0\\ 1&2&1&0&0\\ \end{pmatrix}

\begin{pmatrix} 1&0&0&0&0&0&0\\ 0&0&0&0&0&0&0\\ 1&1&0&0&0&0&0\\ 0&0&0&0&0&0&0\\ 1&2&1&0&0&0&0\\ 0&0&0&0&0&0&0\\ 1&3&3&1&0&0&0\\ \end{pmatrix}

Thanks for your help.

share|improve this question

migrated from math.stackexchange.com Dec 9 '12 at 13:24

This question came from our site for people studying math at any level and professionals in related fields.

    
luis, I updated my answer. Hopefully it is now easier to understand and more practical. –  Mr.Wizard Dec 9 '12 at 20:28

3 Answers 3

Simplistically you could use Binomial and Array, and then interleave zero rows. (See the edit history of this post for an example.) A better method is to craft a function using Binomial that returns the right value directly, which would be useful if you don't want to generate the entire array at once. The function below indexes from zero, which is unusual in Mathematica but aligns with Binomial.

f1 = If[OddQ @ #, 0, Binomial[#/2, #2]] &;

A 7 x 7 matrix:

Array[f1, {7, 7}, 0] // MatrixForm

Mathematica graphics

For large matrices you will find that other methods to generate the underlying triangle are faster:

f2[n_] :=
  With[{pt = NestList[{0, ##} + {##, 0} & @@ # &, {1}, n - 1]},
    ArrayFlatten @ 
      Riffle[{{PadRight[pt, {n, 2 n - 1}]}} ~Transpose~ {3, 2, 1}, {{0}}]
  ]

This function builds the full array to a specified degree:

f2[4] // MatrixForm

Mathematica graphics

It is significantly faster than the first function:

Array[f1, {1500, 1500}, 0]; // Timing // First

f2[1500]; // Timing // First

2.668

0.687

There are going to be faster methods using the symmetry of the triangle and compilation but I will not elaborate unless asked, as the question does not mention performance.

share|improve this answer

One way :

f[n_?IntegerQ] := Riffle[PadRight[#, 2 n + 1] & /@ 
   Outer[Binomial[#1, #2] &, Range[0, n], Range[0, n]], 
     {ConstantArray[0, 2 n + 1]}]

f[2] // MatrixForm

mat2

share|improve this answer

Something like this?

makeArray[nu_] :=
 Riffle[
  PadRight[#, 2*nu - 1] & /@ Table[
    Binomial[n, k],
    {n, 0, nu - 1},
    {k, 0, n}
    ],
  ConstantArray[0, {1, 2*nu - 1}]
  ]

makeArray[4] // MatrixForm

Mathematica graphics

share|improve this answer

Your Answer

 
discard

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