# Handle matrices and vectors with general dimension

I have a matrix of $n \times n$ dimension: $$K - \omega^2 M = \begin{pmatrix} 2\omega_0^2 - \omega^2 & - \omega_0^2 & 0 & \cdots & 0 \\ - \omega_0^2 & 2\omega_0^2 - \omega^2 & -\omega_0^2 & \cdots & 0 \\ 0 & -\omega_0^2 & 2\omega_0^2-\omega^2 & \cdots & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & 0 & \cdots & 2\omega_0^2-\omega^2 \end{pmatrix}$$

And I want a solution to the equation: $$\left( K - \omega^2 M \right) \cdot \mathbf{c} = 0, \quad \mathbf{c} = \left( c_1, c_2, \cdots, c_n \right)^T$$

The first problem is obviously the characteristic equation:

$$\det \left( K - \omega^2 M \right) = 0$$

which is too hard for Mathematica to handle (couldn't simplify even when I plugged in general eigenvalue), so I carried this manually and the eigenvalues are:

$$\omega_k = 2 \omega_0 \cos \frac{k \pi}{2(n+1)}, \quad 1 \leq k \leq n$$ My problem is to obtain eigenvectors for general case: $n$, which I can set to any integer value and have it evaluated. Definition of matrix is simaple so far:

M = Table[Table[KroneckerDelta[i, j] (2 - a^2) -
KroneckerDelta[i, j + 1] - KroneckerDelta[i, j - 1], {j, 1,
n}], {i, 1, n}]


Where I can set $n$ to any value ($n = 5$ for example). Notice that this is a nondimensionalised matrix with $\omega = a \omega_0$ and in sake of clarity $\omega_0$ was cancelled $n$-times.

Now here comes the problem: I will need a column vector of arbitrary length, but I can't write:

c = Table[ci, {i, 1, n}]


because Mathematica does not recognise "i" being a variable in "ci". Although this is desired result for $n = 5$:

c = {c1, c2, c3, c4, c5}


The next thing is solution to the problem with correct eigenvalues:

S1 = Solve[Dot[M/.a->2Cos[1 Pi/(2n+2)],c] == 0, c]
S2 = Solve[Dot[M/.a->2Cos[2 Pi/(2n+2)],c] == 0, c]
S3 = Solve[Dot[M/.a->2Cos[3 Pi/(2n+2)],c] == 0, c]
...
Sn = Solve[Dot[M/.a->2Cos[n Pi/(2n+2)],c] == 0, c]


Again, how can I rewrite this for some arbitrary eigenvalue, so I can handle it in general form?

The desired result is several lists of eigenvectors:

L1 = Flatten[{c1 /. S1, c2 /. S1, c3 /. S1, ..., cn /. Sn}]
L2 = Flatten[{c1 /. S2, c2 /. S2, c3 /. S2, ..., cn /. Sn}]
L3 = Flatten[{c1 /. S3, c2 /. S3, c3 /. S3, ..., cn /. Sn}]
...
Ln = Flatten[{c1 /. Sn, c2 /. Sn, c3 /. Sn, ..., cn /. Sn}]


And the final step is to plot all solutions:

Table[ListPlot[Li],{i,1,n}]


Now all of this is obtainable by simply invoking:

e = Eigenvectors[M]


Which is simply a matrix of eigenvectors (one can think of a basis in which $M$ is diagonal). The problem is, that Mathematica doesn't really know about the beauty and simplicity of eigenvalues of such a matrix. As a result, the eigenvalues for e.g. $n = 6$ are pretty nasty, involving complex numbers and such - it's because $\cos \frac{\pi}{7}$ is really not a nice closed-form expression. Then the problem is, that Mathematica cannot find eigenvectors for $n = 6$ in suitable form (a typical eigenvector is "2-a^2 - Root[...]" with strange things like #1) when the problem is obviously ONLY in eigenvalues (when plugging some eigenvalue manually I can obtain corresponding eigenvector).

My question is: how can I generalize those expressions for $\mathbf{c}$, $S_n$, $L_n$ and so on, or, alternatively, how can I obtain eigenvectors for every $n$ with Eigenvectors[M] without some time-consuming procedure involving #1 and Root[...] and so they are SORTED by corresponding eigenvalues?

P.S.: I know that eigenvectors are stationary waves.

• Since your matrix is Toeplitz, your eigenvector components are also expressible in terms of trigonometric functions. If you're interested, I can write up a solution. – J. M.'s ennui Jul 12 '15 at 13:14
• Yes, the eigenvector components are $\sin \frac{(n-k+1)\pi}{n+1} i$, $n$ is dimension of problem, $k$ is number of eigenvector a $i$ is it's the component. – user16320 Jul 12 '15 at 14:54
• So you know the result already; why not use that so you're assured that your eigenpairs are arranged in the manner you want? – J. M.'s ennui Jul 12 '15 at 14:55
• Oh, and another thing: look up SparseArray[] and Band[]. – J. M.'s ennui Jul 12 '15 at 14:57

As @GuessWhoItis mentioned, some or all of this can be done analytically. But I'll answer your question regarding Mathematica syntax, as it seems to be the goal of what you're trying to achieve here.

Mathematica does not recognise "i" being a variable in "ci".

The best way to deal with this is to define

cVector=Table[c[i],{i,n}];


or alternatively,

cVector=Array[c,n];


Then, treat each c[1] as c1, c[2] as c2 and so on. In some cases you can also use Subscript to do that, but this is discouraged and should be avoided.

Now, regarding your question about the eigenvectors. If you have a matrix $M$ and you already know that $\Lambda$ is an eigenvalue, what you are actually looking for is the NullSpace of the matrix $M-\Lambda I$. Therefore, you don't even need to define cVector. The following code does everything:

n = 8;
M = Table[Table[
KroneckerDelta[i, j] (2 - a^2) - KroneckerDelta[i, j + 1] -
KroneckerDelta[i, j - 1], {j, 1, n}], {i, 1, n}];
S = Table[NullSpace[M /. a -> 2 Cos[i Pi/(2 n + 2)]], {i, n}]


(I picked some value for n so that the thing would run)

• Yes, this is working great. Any idea on the problem if I would not know the eigenvalues? I noticed Mathematica can't really evaluate determinant with them to zero and those strange Root[...] and so on...Besides that, great answer, thank you. – user16320 Jul 12 '15 at 14:56