1

I want to write a matrix in Mathematica by programming. How can I write it?

The matrix is :

$ M= \begin{bmatrix} 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \end{bmatrix} $

Considering $p$- Number of rows and $2n+1$- Number of columns I wrote the following program which is added. But this code is not working. I can form a matrix by matrix tool option. but it is 1000 entries or more that will a problem.

enter image description here

a b
  • 99
  • 3

2 Answers2

1
p = 2; n = 5;
mat = ConstantArray[0, {p, 2 n + 1}];
mat[[1, Floor[n/2 + 1]]] = 1;
mat // MatrixForm // TeXForm

$\left( \begin{array}{ccccccccccc} 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ \end{array} \right)$

kglr
  • 394,356
  • 18
  • 477
  • 896
0

How about this

yourMatrix[p_, n_] := SparseArray[{1, Floor[n/2 + 1]} -> 1, {p, 2 n + 1}]

yourMatrix[2, 5] // MatrixForm