1
$\begingroup$

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

$\endgroup$
1
$\begingroup$
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)$

$\endgroup$
0
$\begingroup$

How about this

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

yourMatrix[2, 5] // MatrixForm
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.