I am having problems with creating a vector of 1s of length (for example) n=4.
I tried
ones=Tuples[{1},4]
This outputs {{$1,1,1,1$}}
The problem I have here, is that I want to concatenate this $1$'s vector with an identity matrix. See below, I transpose the ones vector to get a column vector
onesT = Transpose[ones]
The above command outputs {{$1$},{$1$},{$1$},{$1$}} (which I think is what I want because it denotes a $4 \times 1$ column vector)
I then join with the $4 \times 4$ identity matrix in order to achieve my desired matrix.
identity = IdentityMatrix[4]
matrix = Join[identity, onesT]
However, this outputs {{$1,0,0,0$},{$0,1,0,0$},{$0,0,1,0$},{$0,0,0,1$},{$1$},{$1$},{$1$},{$1$}}
But I want it to output {{$1,0,0,0$},{$0,1,0,0$},{$0,0,1,0$},{$0,0,0,1$},{$1,1,1,1$}}.
Is there a way of either:
- Creating a vector of $1$'s of length $n$, other than using Tuples[], so as to avoid the formatting issues
- Concatenating these two matrices (onesT and identity) so as to avoid formatting issues (I tried to use Flatten[] at various stages in the code, and this did not seem to work)
n = 4; Join[IdentityMatrix[n], {ConstantArray[1, n]}]
? $\endgroup$onesT = Table[1, 4] identity = IdentityMatrix[4] matrix = Join[identity, {onesT}]
$\endgroup$Join[IdentityMatrix[n], ConstantArray[1, {1, n}]]
. $\endgroup$SparseArray[{{i_, i_} -> 1, {n + 1, _} -> 1}, {n + 1, n}]
or evenSparseArray[{i_, i_} | {n + 1, _} -> 1, {n + 1, n}]
. $\endgroup$ones = Tuples[{1}, 4] identity = IdentityMatrix[4] matrix = Join[identity, ones]
$\endgroup$