Hello Xiangfeng,
I have corrected the code to work with euclideancomplexfactory. I am attaching the code below. The changes I made are that to treat s'*C*s and s'*C'*s as different entities and carefully evaluate the gradient and the directional derivative of gradient. For numerical reasons, there is a small residue of imaginary part left in computing (s'*C*s)*(s'*C'*s), so I had to return the real part of it. Now the gradient and hessians check pass!
C = rand(n)+rand(1)*1i*rand(n);
manifold = euclideancomplexfactory(n);
problem.M = manifold;
% Note that s'*C*s is the complex conjugate of s'*C'*s.
% Yet (s'*C*s)*(s'*C'*s) might have some residual imaginary
% part, so we have return real part of the cost function.
problem.cost = @(s) real(1/2*(s'*C*s)*(s'*C'*s));
problem.egrad = @(s) (s'*C'*s)*(C*s) + (s'*C*s)*(C'*s);
problem.ehess = @(s,v) (s'*C'*s)*(C*v) + (s'*C'*v)*(C*s) + ...
(v'*C'*s)*(C*s) + (s'*C*s)*(C'*v)+ ...
(s'*C*v)*(C'*s)+ (v'*C*s)*(C'*s);
checkgradient(problem); pause;
checkhessian(problem); pause;
end
Regards,
Jayadev.