I would like to create a function which can can take a symbolic square matrix $m$ and returns $m \otimes I$. Where $I$ is the idenity operator of same dimensions as $m$. The actual function I am interested in is more complicated but this is the minimal functionality that I am interested in.
An implementation that would work for non-symbolic (I just mean concrete) matrices m could for example be the following
mKronI[m_] := KroneckerProduct[m, IdentityMatrix[Length[m]]]
Then, inserting some specific matrix, say $$ m = \left( \begin{matrix} 1 & 0 \\ 0 & 0 \end{matrix} \right) $$ should return $$ \left( \begin{matrix} 1 & 0 \\ 0 & 0 \end{matrix} \right) \otimes \left( \begin{matrix} 1 & 0 \\ 0 & 1 \end{matrix} \right) = \left( \begin{matrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \end{matrix} \right)$$ Indeed:
In[]:m = {{1, 0}, {0, 0}};
In[]:mKronI[m]
Out[]:{{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
However, such a function returns an error when a symbolic variable is passed as it is unable to determine the Length of this variable.
Would it be possible to let the function simply return 'its definition' in such a case? Such that we would have
In[]:answ = mKronI[m]
Out[]:KroneckerProduct[m, IdentityMatrix[Length[m]]]
which then would also ensure that whenever m will be specified later, answ will automatically be evaluated to the correct value.
In simple terms I would like similar behavior for the function as we have for the following trivial example which mixes symbolic variables and variables for which the value is specified
In[]:c = a + b
Out[]:a + b
Then, if we specify b
In[]:b = 1
And check the value for c, we get
In[]:c
Out[]:1+a
I hope my question is clear. I have looked into a number of posts Implementing the symbolic identity matrix and Symbolic tensor simplifications and the identity matrix but I don't understand the answers given there well and also I doubt if they would help me. I also fiddled around with some things as Assuming[m \[Element] Matrices[{n, n}], KroneckerProduct[m, IdentityMatrix[n]]]) but so far without luck.
Thanks in advance for any help.
mKronI[m_] /; MatrixQ[m] := KroneckerProduct[m, IdentityMatrix[Length[m]]]– Daniel Huber May 22 '21 at 16:43SetDelayedforansw? Or not invokemKronIuntil you have an actual matrix set for your variable you use inmKronI? Are you aware that you don’t have to use onlymin yourmKronI? You could set something likematrixThatIsNotmto a matrix and invokemKronI[matrixThatIsNotm]. I apologize if this is a misunderstanding of your problem, but it seems to me that you could simply change slightly your method of programming to not generate this problem? – CA Trevillian May 22 '21 at 18:52Condition. @CA Trevillian, if I useSetDelayedforanswit will not directly yield an error, but it will the first time I use it somewhere. But I don't understand your suggestion. What do you mean by setting something to a matrix? Similar to Element[m, Matrices[{n, n}]]? But you may be right about my rogramming methods,maybe I should reconsider them. – Alwin May 22 '21 at 19:42