For simulation purpose I need to generate $n\times n$ Hermitian matrix $H$ many times. However, all $H$ must satisfy the following inequalities: $$X\geq H\geq-X,$$
where $X$ is known $n\times n$ positive definite matrix and $X\geq H$ means that $X-H$ is positive semidefinite.
Current method on Matlab:
Find largest eigenvalue of $X$, lets call it $\lambda$.
Generate random diagonal matrix $D$ with diagonal elements being between $-\lambda$ and $\lambda$ .
Set $H=VDV^*$, where $V$ is some unitary matrix.
beta=2; alpha=10; for i=1:10 T=2.*rand(10,10)-1*ones(10,10)+i*(2.*rand(10,10) -1*ones(10,10)); [U,S,V]=svd(T); rX=cosd(alpha).*((beta-1/beta).*rand(10,1)+1/beta); Ah=U*diag(rX)*U'; X=Ah*tand(alpha); rH=(2).*rand(10,1)-1; H=sqrt(X)*U*diag(rH)*U'*sqrt(X); [eig(X-H) eig(H+X)] end
Generated $H$ doesn't satisfy above inequalities. I don't understand where I am doing mistake, please help me to understand.
That all eigenvalues of $H$ lie between $\lambda_\max(X)$ and $-\lambda_\max(X)$ is only a necessary condition for $-X\le H\le X$. It is not a sufficient condition. Consider $X=\operatorname{diag}(3,1)$ and $H=2I$ for instance.
One way to generate $H$ is to use the fact that $-X\le H\le X$ if and only if $-I\le X^{-1/2}HX^{-1/2}\le I$. So, if $U$ is a random unitary matrix, $D$ is a random real diagonal matrix whose diagonal entries lie inside the interval $[-1,1]$, then $H=X^{1/2}UDU^\ast X^{1/2}$ will be a Hermitian matrix that lies between $-X$ and $X$ in the positive semidefinite partial ordering.