I am new to Mathematica. Here is my problem:
Given the matrix
$\qquad M = \begin{pmatrix} 2 & -1 \\ 1 & 2 \end{pmatrix}$,
sum the overlap (inner-product) of it's eigenvectors
$\qquad \bigg\{\begin{pmatrix}i \\1 \end{pmatrix},\begin{pmatrix}-i \\1 \end{pmatrix} \bigg\}$.
To this end, I first reshape to form arrays with correct dimensions. I am then able to generate and print the overlap values in the form of a 1x1 array for each overlap pair, but am then having difficulty appending the result to a list as can bee seen by the empty list L2 in the output.
Can anyone advise me on what the problem is wrong with the attached code?
Appending Matrices to Lists
M = {{2, -1}, {1, 2}};
Eig = Eigenvectors[M]
Eval = Eigenvalues[M] ;
L1 = {};
L2 = {};
For[i = 1, i <= Length[M], i++,
AppendTo[L1, ArrayReshape[Eig[[i]], {Length[M], 1}]]]
For[i = 1, i <= Length[M], i++,
For[j = 1, j <= Length[M], j++ ,
Print[Dot[ConjugateTranspose[L1[[i]]], L1[[j]]]]]]
For[i = 1, i <= Length[Gd2], i++,
For[j = 1, j <= Length[Gd2], j++ ,
Append[L2 , Dot[ConjugateTranspose[L1[[i]]], L1[[j]]] ]]]
Print[L1]
Print[L2]
{{I, 1}, {-I, 1}}
During evaluation of In[2198]:= {{2}}
During evaluation of In[2198]:= {{0}}
During evaluation of In[2198]:= {{0}}
During evaluation of In[2198]:= {{2}}
During evaluation of In[2198]:= {{{I},{1}},{{-I},{1}}}
During evaluation of In[2198]:= {}
m = {{2, -1}, {1, 2}}; Dot @@ Eigenvectors[m]? – MarcoB Jan 13 '21 at 15:32ForandAppendTois almost always very slow. I think, for example, yourFor[i = 1, i <= Length[M], i++, AppendTo[L1, ArrayReshape[Eig[[i]], {Length[M], 1}]]]is better stated asL1 = List /@ Eig. See https://mathematica.stackexchange.com/questions/18393/what-are-the-most-common-pitfalls-awaiting-new-users/18396#18396 – Patrick Stevens Jan 13 '21 at 15:33Appendwhere I think you wantedAppendTo– Simon Woods Jan 13 '21 at 19:39