0001 function complextest_AD1()
0002
0003
0004
0005 if isempty(which('spherecomplexfactory'))
0006 error(['You should first add Manopt to the Matlab path.\n' ...
0007 'Please run importmanopt.']);
0008 end
0009
0010
0011 assert(exist('dlarray', 'file') == 2, ['Deep learning tool box is '...
0012 'needed for automatic differentiation.\n Please install the'...
0013 'latest version of the deep learning tool box and \nupgrade to Matlab'...
0014 ' R2021b if possible.'])
0015
0016
0017 n = 100;
0018 A = randn(n) + 1i*randn(n);
0019 A = .5*(A+A');
0020
0021
0022 S = spherecomplexfactory(n);
0023 manifold.x = S;
0024 manifold.y = S;
0025 problem.M = productmanifold(manifold);
0026
0027
0028
0029
0030
0031
0032 problem.cost = @(X) -creal(cprod(cprod(ctransp(X.x), A), X.y));
0033
0034
0035 problem = manoptAD(problem);
0036
0037
0038 figure;
0039 checkgradient(problem);
0040 figure;
0041 checkhessian(problem);
0042
0043
0044 [x, xcost, info] = trustregions(problem);
0045
0046
0047 ground_truth = svd(A);
0048 distance = abs(ground_truth(1) - (-problem.cost(x)));
0049 fprintf('The distance between the ground truth and the solution is %e \n',distance);
0050
0051
0052 end