# KroneckerProduct and Transpose [closed]

I need to take the KroneckerProduct of the an $n \times n$ identity matrix and a $1 \times n$ row vector (let's call it $T$), both of which are numerical.

As in: $S=I \otimes T$ (where $\otimes$ denotes the Kronecker product)

More specifically I have:

k = 3;

chebT[0] = 1;
chebT[1] = 2*t - 1;

chebT[n_] := chebT[n] = Expand[2*(2*t - 1)*chebT[n - 1] - chebT[n - 2]];
Tstar = Table[chebT[n], {n, 0, k}]

i = IdentityMatrix[k + 1] // MatrixForm
S = KroneckerProduct[i, Transpose[Tstar]] // MatrixForm


but this gives the message:

Transpose::nmtx: The first two levels of the one-dimensional list {1,-1+2 t,1-8 t+8 t^2,-1+18 t-48 t^2+32 t^3} cannot be transposed. >>

I can use loops to manually calculate the Kronecker product, but I would rather not. What am I doing wrong? Do I need to use Array instead of Table?

Edited to include the whole (and correct) code.

-

## closed as off-topic by m_goldberg, bobthechemist, Michael E2, Kuba, Yves KlettFeb 5 at 11:29

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – m_goldberg, bobthechemist, Michael E2, Kuba, Yves Klett
If this question can be reworded to fit the rules in the help center, please edit the question.

One (incomplete) observation: do not use MatrixForm in a definition this way! A matrix wrapped in MatrixForm won't be usable as a matrix in Mathematica. (This is a common misunderstanding with people new to Mathematica.) Also, your code is incomplete and contains some things that look like mistakes. For example, there's no initial value given for chebT[0] and Tstar is not a function yet you seem to be using it as one, as in Tstar[n]. Can you correct these and post complete code please, in the spirit of sscce.org ? –  Szabolcs Feb 4 at 17:01
I would also check the Dimensions of T. Something with Dimensions of {k} is not the same as {k,1} or {1,k}. –  chuy Feb 4 at 17:05
What do you mean by won't be useable? I only use MatrixForm to easily read the output of large matrices, I was under the assumption it didn't affect any Mathematica operations. How do I use it correctly? –  gKirkland Feb 4 at 17:05
You are assigning something wrapped in MatrixForm to i. {{1,2},{3,4}} is a matrix usable with functions such as Dot. MatrixForm[{{1,2},{3,4}}] isn't. Make sure you only use MatrixForm at the very final step to affect the formatting of the output but you don't assign expressions wrapped by it to variables. –  Szabolcs Feb 4 at 17:07
Another thing I notice: note the difference between {1,2,3}, {{1,2,3}} and {{1},{2},{3}}. The first one is a vector, the 2nd and 3rd are matrices ("row matrix", "column matrix"). A vector can't be transposed, only a matrix can. Your code seems to try to transpose a vector. In Mathematica there typically isn't any need to use row/column matrices. Simple one dimensional vectors will do. Other systems like MATLAB or Octave are limited in that they simply do not support true 1D vectors, so people coming form this systems try to continue working in the matrix paradigm. –  Szabolcs Feb 4 at 17:10

1. Do not use m = MatrixForm[{{1,2},{3,4}}] because m will carry the MatrixForm wrapper with it and will prevent functions from operating on the matrix. Please see point 6 here.

2. It is not possible (nor necessary) to transpose a one dimensional vector.

Unlike some other numerical software such as MATLAB, Mathematica does not solely operate on matrices. Instead it works with arbitrary dimensional tensors, including one-dimensional vectors. {1,2,3} represent a 1D vector. {{1,2,3}} represent a row matrix (2D structure). {{1},{2},{3}} represents a column matrix. Operations such as Dot work on vectors directly. It is typically more convenient to work with simple vectors in Mathematica instead of row/column matrices.

To sum up, change the last two lines of your code to this:

i = IdentityMatrix[k + 1]
S = KroneckerProduct[i, Tstar]

-
Note to other users: I made this community wiki, so feel free to edit, expand, improve it. –  Szabolcs Feb 5 at 0:48