DCP error with exponential function

I am writing an optimization code which is essentially this:
G = constant vector of size (40,1)
K = constant vector of size (37,1)
A = constant vector of size (50,1)
Meas = constant vector of size (50,1) (corresponds to the experimentally measured data)

I need to optimize a variable x of size (50,1) such that:

cvx_begin
cvx_solver mosek
variable x(50,1)
G = Exp_conv(x,A,G, K);
minimize(norm(G-Meas))
cvx_end

where Exp_conv is a function defined as:

function X = Exp_conv (x,A,G,K)

for i = 1:50
        E = A(i).*((exp(x(i).*K)));  %returns a (37,1) sized vector
        n = 40-size(K,1);
        E_final = [zeros(n,1);E];   %zero pad at one end to form a vector of the size of G
        X(i,1) = sum(G.*E_final);  %the output is (50,1) sized vector, corresponds to the observed data
           
end
end

The error is that norm cannot be calculated (cause the input to norm should be affine). Essentially, the objective norm(G-Meas) corresponds to a data fidelity term, where I try to minimize the error between the function constructed with the variable and the observed data. I have tried to think of any alternative formulation for this but cannot do it. Would be glad if anyone can suggest anything (hoping there is one!)

Make exp_xdottimesK your declared 50 by 1 variable instead of x. Then the argument of norm will be affine. You can recover x from the optimal value of exp_xdottimesK after CVX has performed the optimization.

Thanks. Its a clever work around. But if I understand correctly, this exp xdottimesK would amount to having a 37 x 1 vector corresponding to each of the x (which is of size 50,1) which i am not sure how to handle here. I mean, I need to have each of the elements of the exp(x(i).K) to dot multiply with G.
A different question though: can we use expressions like xexp(x) which are not allowed in cvx by calling the same solver (mosek) outside cvx ? or is this something common across all platforms?

Sorry, i wasn’t paying attention to the dimensions and messed that up. If you used variable exp_x instead of exp(x), there would be a variable to the K, which would lead to a non-affine argument of norm.

So now the question, have you proved this is a convex optimization problem? If so, how?

Almost anything which can be done with Mosek via some front-end other than CVX can be done using CVX, but the CVX code is not necessarily the easiest to write in all cases, even though it is in many cases.

So, the dreaded convexity proof.
Let us assume that the variable that I need to retrieve has size (2,1). (can be envisaged as x = [x1 x2])
Let K be a constant vector of size (3,1). [K1 K2 K3]
Let G be a constant vector of size (3,1). [G1 G2 G3]
In this case, my quantity of interest is a vector X which represents the following quantity:
X = [G1exp(K1*x1)+G2exp(K2*x1)+G3exp(K3*x1) G1exp(K1*x2)+G2exp(K2*x2)+G3exp(K3*x2)]

exp(ax) is a convex function and so the sum of exp(ax) should be a convex function too. So, I concluded that the vector X contains convex terms.
Next step is to minimize the error between these terms and the observed value. Let the observed value be represented by Meas. This Meas too has two elements. Each element correspond to the respective elements of X. In other words, I want to minimise the difference between X and M, i.e:
[X(1)-M(1) X(2)-M(2)].
The obvious way to minimise this was to take the norm. Since, X was a convex entity, it seemed okay to me until this requirement for the argument of norm to be affine popped up. I know this is not expected at this forum to ask this, but I am really not able to figure out why this is not affine (PS: I did go through the CVX manual).

Anyways, your idea of declaring exp_xdottimesK does seem plausible. Its just that it increases the number of variables. So just to confirm I think you mean I define something like
y = A(i).*((exp(x(i).*K))) as my declared variable. I did a mini test like this:

cvx_begin
cvx_solver mosek
variable y(40,50)
for i = 1:50
    E = y(:,i);
    E_final = [zeros(3,1);E];
    X(i,1) = sum(G.*E_final);
end
minimize(norm(X-Meas))
cvx_end

The idea is once I get y as a 40 x 50 matrix, I need to recover the (50,1) vector, by using the (40,1) K values. More specifically, each column represents the dot product corresponding to the one of the 50 elements of x.
So, when I run this, it doesn’t show any DCP error. The code runs with status as primal and dual feasible. I can’t say if the solution is good or not because I didn’t do the ‘post processing’ of evaluating the values of x from the solution y given by CVX.

So another question (last I promise)

What if instead of the above expression of y = A(i).*((exp(x(i).*K))) , I had
y = (A./x).*((exp((1/x).*K)))
This is convex only for x>0 and I understand not acceptable as per DCP rules… But I wonder if a similar substitution with another variable y could be used in this approach where I add a constraint of y>0

At this point, I am rather confused by your notation. I will leave it to you to determine whether your code in the preceding post is a correct formulation of your problem, and whether you can recover the variables whose optimal values you really want from the solution of that problem.