eigenvalue decomposition using matlab

I would like to diagnolize a rank-1 matrix using the well known eigenvalue decomposition as $$\mathbf{U}^H\mathbf{A}\mathbf{U} = diag (M, 0,\cdots, 0)$$, where $$\mathbf{A}$$ is a Hermitian matrix and $$\mathbf{U}$$ is a unitary matrix.

While if we use eig.m in matlab, the resulting $$\mathbf{U}$$ fails to satisfy the property of unitary matrix $$\mathbf{U}^H\mathbf{U} = \mathbf{I}_{M}$$ due to the unit round-off error and the use of \pi.

What should I do?

The code can be given:

    clc
clear all
close all

c           = 340;
j           = sqrt(-1);
theta_s     = 0;
theta_s     = theta_s*pi/180;

M           = 6;
delta       = 0.012;
M_vector    = (0:M-1)';
theta       = 0:0.1:360;
theta       = theta*pi/180;

f           = 4000;

%% eigenvalue decomposition of matrix
omega       = 2*pi*f;
d           = exp(-j*omega*M_vector*delta/c);
h_DS        = 1/M*d;
A           = d*d';

[U,D]       = eig(A);

• Use of $\pi$??? ${}$ – copper.hat Apr 28 at 3:56
• The entries in matrix $\mathbf{A}$ relate to $\pi$, and the $pi$ in matlab is an approximate value. – chen xi Apr 28 at 3:58
• Does it badly fail to satisfy it, or is it satisfying up to double-precision round-off? – eyeballfrog Apr 28 at 4:04
• Badly failed. I can give a test code – chen xi Apr 28 at 4:07
• The matrix A is a Hermitian matrix. – chen xi Apr 28 at 4:15

Due to round-off errors, MATLAB isn't recognizing that your matrix is Hermitian. You can fix this easily by averaging A with its Hermitian transpose:

>> ishermitian(A)

ans =

logical

0

>> B=(A+A')/2;
>> ishermitian(B)

ans =

logical

1


Once you've done this, U'*U=I as expected.

>> [U,D]=eig(B);
>> U'*U

ans =

Columns 1 through 4

1.0000 + 0.0000i  -0.0000 + 0.0000i   0.0000 + 0.0000i  -0.0000 - 0.0000i
-0.0000 - 0.0000i   1.0000 + 0.0000i  -0.0000 - 0.0000i  -0.0000 - 0.0000i
0.0000 - 0.0000i  -0.0000 + 0.0000i   1.0000 + 0.0000i   0.0000 - 0.0000i
-0.0000 + 0.0000i  -0.0000 + 0.0000i   0.0000 + 0.0000i   1.0000 + 0.0000i
0.0000 - 0.0000i   0.0000 - 0.0000i   0.0000 - 0.0000i  -0.0000 + 0.0000i
-0.0000 + 0.0000i  -0.0000 - 0.0000i   0.0000 - 0.0000i   0.0000 + 0.0000i

Columns 5 through 6

0.0000 + 0.0000i  -0.0000 - 0.0000i
0.0000 + 0.0000i  -0.0000 + 0.0000i
0.0000 + 0.0000i   0.0000 + 0.0000i
-0.0000 - 0.0000i   0.0000 - 0.0000i
1.0000 + 0.0000i   0.0000 + 0.0000i
0.0000 - 0.0000i   1.0000 + 0.0000i

• I really appreciate your help. Thank you!!! – chen xi Apr 28 at 4:38