Problems with spectral decompositon of a $4 \times 4$ matrix [duplicate]

Given a matrix $$M$$ with eigenvalues $$\lambda_1, \lambda_2, \lambda_3,\lambda_4$$ and the corresponding eigenvectors $$|v1\rangle,|v2\rangle,|v3\rangle,|v4\rangle$$. One can write

$$M = \lambda_1 |v1\rangle\langle v1| + \lambda_2 |v2\rangle\langle v2| + \lambda_3 |v3\rangle\langle v3| + \lambda_4 |v4\rangle\langle v4|$$.

For the matrix $$M$$ below, $$\lambda_1 = \lambda_2 =0$$, however, $$\lambda_3 |v3\rangle\langle v3| + \lambda_4 |v4\rangle\langle v4| \neq M$$.

Edit

In the suggested duplicate answer, the problem is with the ordering of eigenvalues. However, in my case, it seems that the problem arises from the syntax used for vectors/matrices, or may be something different?

M =
{{1/4 (3 + Cos[2 t ω]), 1/4 I Sin[2 t ω], 1/2 I Sin[t ω], Cos[t ω]},
{-(1/4) I Sin[2 t ω], 1/2 Sin[t ω]^2, 0, -(1/2) I Sin[t ω]},
{-(1/2) I Sin[t ω], 0, 1/2 Sin[t ω]^2, -(1/4) I Sin[2 t ω]},
{Cos[t ω], 1/2 I Sin[t ω], 1/4 I Sin[2 t ω], 1/4 (3 + Cos[2 t ω])}};

v3 = ({{-1}, {-I Cot[(t ω)/2]}, {I Cot[(t ω)/2]}, {1}});

v3D = (-{{1, I Cot[(t ω)/2], -I Cot[(t ω)/2], 1}});

v4 = ({{1}, {-I Tan[(t ω)/2]}, {-I Tan[(t ω)/2]}, {1}});

v4D = ({{1, I Tan[(t ω)/2], I Tan[(t ω)/2], 1}});

FullSimplify[v3D.v3]


{{-2 Cot[(t ω)/2]^2}}

FullSimplify[v4D.v4]


{{2 Sec[(t ω)/2]^2}}

FullSimplify[
v3D.v3/(-4 Cot[(t ω)/2]^2) + v4D.v4/(4 Sec[(t ω)/2]^2)]


{{1}}

FullSimplify[
(1 - Cos[t ω]) v3.v3D/(-4 Cot[(t ω)/2]^2) +
(1 + Cos[t ω]) v4.v4D/(2 Sec[(t ω)/2]^2)] // MatrixForm

MatrixForm[
{{(1/32)*(4 + 23*Cos[t*ω] + 4*Cos[2*t*ω] + Cos[3*t*ω])*Sec[(t*ω)/2]^2,
(1/8)*I*(4*Sin[t*ω] + Sin[2*t*ω] - 4*Tan[(t*ω)/2]),
(1/8)*I*(Sin[2*t*ω] + 4*Tan[(t*ω)/2]),
(1/32)*(4 + 23*Cos[t*ω] + 4*Cos[2*t*ω] + Cos[3*t*ω])*Sec[(t*ω)/2]^2},
{(-(1/8))*I*(Sin[2*t*ω] + 4*Tan[(t*ω)/2]),
(1/2)*(2 + Cos[t*ω])*Sin[(t*ω)/2]^2,
(1/2)*Cos[t*ω]*Sin[(t*ω)/2]^2,
(-(1/8))*I*(Sin[2*t*ω] + 4*Tan[(t*ω)/2])},
{(-(1/8))*I*(4*Sin[t*ω] + Sin[2*t*ω] - 4*Tan[(t*ω)/2]),
(1/2)*Cos[t*ω]*Sin[(t*ω)/2]^2,
(1/2)*(2 + Cos[t*ω])*Sin[(t*ω)/2]^2,
(-(1/8))*I*(4*Sin[t*ω] + Sin[2*t*ω] - 4*Tan[(t*ω)/2])},
{(1/32)*(16 + 7*Cos[t*ω] + 8*Cos[2*t*ω] + Cos[3*t*ω])* Sec[(t*ω)/2]^2,
(1/8)*I*(Sin[2*t*ω] + 4*Tan[(t*ω)/2]),
(1/8)*I*(4*Sin[t*ω] + Sin[2*t*ω] - 4*Tan[(t*ω)/2]),
(1/32)*(16 + 7*Cos[t*ω] + 8*Cos[2*t*ω] + Cos[3*t*ω])*Sec[(t*ω)/2]^2}}]


Since the dot product of two vectors should be a scalar, you should probably write in the normal Mathematica way. For example:

v3 = {-1, -I Cot[(t ω)/2], I Cot[(t ω)/2], 1};
v3D = -{1, I Cot[(t ω)/2], -I Cot[(t ω)/2], 1};
v3D.v3


-2 Cot[(t ω)/2]^2

Mathematica does not attempt to normalise symbolic eigenvectors. You assume that they are normalised.

I assume that your variables are real, so specify this as an assumption

\$Assumptions = {{t, ω} ∈ Reals};


M = {{1/4 (3 + Cos[2 t ω]), 1/4 I Sin[2 t ω],
1/2 I Sin[t ω],
Cos[t ω]}, {-(1/4) I Sin[2 t ω],
1/2 Sin[t ω]^2,
0, -(1/2) I Sin[t ω]}, {-(1/2) I Sin[t ω], 0,
1/2 Sin[t ω]^2, -(1/4) I Sin[2 t ω]}, {Cos[
t ω], 1/2 I Sin[t ω], 1/4 I Sin[2 t ω],
1/4 (3 + Cos[2 t ω])}};


with eigenvalues and eigenvectors

val = Eigenvalues[M]
(* {0, 0, 1 - Cos[t ω], 1 + Cos[t ω]} *)

vec = Eigenvectors[M] // FullSimplify
(* {{-Cos[t ω], I Sin[t ω], 0,
1}, {-I Sin[t ω], Cos[t ω], 1,
0}, {-1, -I Cot[(t ω)/2], I Cot[(t ω)/2],
1}, {1, -I Tan[(t ω)/2], -I Tan[(t ω)/2], 1}} *)


Verify that we understand Mathematica's convention for eigenanalysis

M.vec[[3]] - val[[3]] vec[[3]] // Simplify
(* {0, 0, 0, 0} *)

M.vec[[4]] - val[[4]] vec[[4]] // Simplify
(* {0, 0, 0, 0} *)


Compute the normalising constants

c3 = Conjugate[vec[[3]]].vec[[3]] // FullSimplify
(* 2 Csc[(t ω)/2]^2 *)

c4 = Conjugate[vec[[4]]].vec[[4]] // FullSimplify
(* 2 Sec[(t ω)/2]^2 *)


Find two rank 1 matrices (with appropriate scaling)

o3 =
val[[3]] Outer[Times, vec[[3]], Conjugate[vec[[3]]]]/c3 //
FullSimplify
(* {{Sin[(t ω)/
2]^4, -(1/2) I Sin[(t ω)/2]^2 Sin[t ω],
1/2 I Sin[(t ω)/2]^2 Sin[t ω], -Sin[(t ω)/
2]^4}, {1/2 I Sin[(t ω)/2]^2 Sin[t ω],
1/4 Sin[t ω]^2, -(1/4) Sin[t ω]^2, -(1/2) I Sin[(
t ω)/2]^2 Sin[t ω]}, {-(1/2) I Sin[(t ω)/
2]^2 Sin[t ω], -(1/4) Sin[t ω]^2,
1/4 Sin[t ω]^2,
1/2 I Sin[(t ω)/2]^2 Sin[t ω]}, {-Sin[(t ω)/
2]^4, 1/2 I Sin[(t ω)/2]^2 Sin[t ω], -(1/2) I Sin[(
t ω)/2]^2 Sin[t ω], Sin[(t ω)/2]^4}} *)

o4 =
val[[4]] Outer[Times, vec[[4]], Conjugate[vec[[4]]]]/c4 //
FullSimplify
(* {{Cos[(t ω)/2]^4,
1/8 I (2 Sin[t ω] + Sin[2 t ω]),
1/8 I (2 Sin[t ω] + Sin[2 t ω]),
Cos[(t ω)/
2]^4}, {-(1/8) I (2 Sin[t ω] + Sin[2 t ω]),
1/4 Sin[t ω]^2,
1/4 Sin[t ω]^2, -(1/8)
I (2 Sin[t ω] + Sin[2 t ω])}, {-(1/8)
I (2 Sin[t ω] + Sin[2 t ω]), 1/4 Sin[t ω]^2,
1/4 Sin[t ω]^2, -(1/8)
I (2 Sin[t ω] + Sin[2 t ω])}, {Cos[(t ω)/
2]^4, 1/8 I (2 Sin[t ω] + Sin[2 t ω]),
1/8 I (2 Sin[t ω] + Sin[2 t ω]),
Cos[(t ω)/2]^4}} *)


And see that they sum to give the rank 2 matrix you specified

o3 + o4 - M // FullSimplify
(* {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}} *)