How do I write a complicated objective function in cvx

The objective function which I try to minimize is

f=sum((abs(R_pq-R_pq_po)).^2,'all')

where R_pq is a known matrix but R_pq_po is

Imn=Amn.*exp(1j*x);
R_pq_po=zeros(2*M-1,2*N-1);
for i=1:length(array_x)
    for ii=1:length(array_y)
        r=0;
        p=array_x(i);
        q=array_y(ii);
        m_min=max(0,-p);
        m_max=min(M-1-p,M-1);
        n_min=max(0,-q);
        n_max=min(N-1-q,N-1);
        for mm=m_min:m_max
            for nn=n_min:n_max
                r=Imn(mm+1,nn+1)*Imn(mm+p+1,nn+q+1)';
                 R_pq_po(p+M,q+N)=R_pq_po(p+M,q+N)+r;
            end
        end    
    end
end

In it, array_x,array_y,M,N and A are all known matrix or array and x is a unkown variable(a matrix) which I try to achieve.
So, how can I write it in cvx? Would be grateful to any help!

Welcome to our community!!!

Have you proven this is convex? It looks rather dubious to me. If not for the imaginary argument of exp (is x real or complex?), perhaps R_pq_po coudl be calculated using CVX’s gp mode, but then you’d be out of luck trying to form the objective function. Unless and until you prove otherwise, I will mark this problem as non-convex.

Actually, I’m not sure whether it’s a convex problem, really sorry!
x is real but Imn is complex, therefore R_pq_po is complex.
The paper I followed actually use fminunc , a nonlinear progeamming solver of MATLAB , to solve this problem. But It needs gradient, which I don’t know how to calculate. So I just try cvx, maybe it can be solved by cvx.
So, how to make sure a problem is convex and what is gp mode. Sorry for my ignorance, if it’s not easy to answer such basic quesitions, I will do researches on my own.
Thanks for your answer!

It seems that you didn’t read the link I posted. CVX is not the right tool for your problem.

Beginning in MATLAB R2020b, when using the problem-based mode for the optimization toolbox, gradients are computed for you by Automatic Differentiation. Even if not, finite differences can be specified for gradient calculation. If you need further help on that, you should post at https://www.mathworks.com/matlabcentral/answers/index

Thanks again! I will read your link carefully!