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