Attempt to add “cvx_problem” to a static workspace

Please post a complete MATLAB session showing all code and (error) messages.

This is the code snippet%%%%%%

cvx_begin quiet
cvx_solver sdpt3
cvx_save_prefs
variables alpha_1 beta_1 x(N,1) ;
% variables beta_1;
% variables x(N,1);
variable X_fin(N,1) complex;
subject to
for t=1:N
abs(x(t))<=alpha_1;
end
subject to
for s=1:N
real(X_fin(s)'f(s)) <= beta_1;
end
subject to
X_fin(1)==0;
if(mod(N,2)==0)
X_fin(N/2+1)==0;
% % real(w(1))==real(w(M/2+1));
for k=1:(N/2-1)
X_fin(k+1)==X_fin(N-k+1)’;
end
else
for i=1:(N-1)/2
X_fin(i+1)==X_fin(N-i+1)’;
end
end
subject to
X_fin==S
x;

cvx_end

ERROR%%%%%%%%%%%%

Error using variable (line 83)
Invalid variable name: complex
This is a reserved word in CVX.
Trying to declare a structured matrix? Use the VARIABLE keyword

Error in variables (line 26)
evalin( ‘caller’, [ 'variable ', varargin{k} ] );

Error in test_new>Min_peak (line 81)
variables alpha_1 beta_1 x(N,1) X_fin(N,1) complex;

Error in test_new>Min_Peak_1 (line 49)
X_opt=Min_peak(N,X) ;

Error in test_new (line 8)
[o,x_opt,X_opt,X_in]=Min_Peak_1(N);

I would make matters easier if you posted the code which generated the error message, not a different version of your code.

Quite simply, you can’t declare `complex` or other variable `keywords` when using `variables` because CVX does not know that they are not additional variable names. So to declare complex, you need to use `variable`.

``````variables alpha_1 beta_1
variable x(N,1) complex
variable X_fin(N,1) complex;
``````

or whatever you want

Hi Mark,
Thank you for your response. This is the same code for which I am getting errors.
As suggested, I have made changes in my code. Now I am getting this error.

%%%%%%%%%%Code
cvx_begin quiet
cvx_solver sdpt3
cvx_save_prefs
variables alpha_1 beta_1;
variable x(N,1) complex;
% variables beta_1;
% variables x(N,1);
variable X_fin(N,1) complex;
subject to
for t=1:N
abs(x(t))<=alpha_1;
end

subject to
for s=1:N
real(X_fin(s)'exp(jangle(f(s))))<=beta_1;
end

subject to
X_fin(1)==0;
if(mod(N,2)==0)
X_fin(N/2+1)==0;
% % real(w(1))==real(w(M/2+1));
for i=1:(N/2-1)
X_fin(i+1)==X_fin(N-i+1)’;
end
else
for i=1:(N-1)/2
X_fin(i+1)==X_fin(N-i+1)’;
end
end

subject to
X_fin==S*x;

cvx_end

%%%%%Error
Error using .* (line 173)
Disciplined convex programming error:
Cannot perform the operation: {complex affine} .* {invalid}

Error in Min_peak_new (line 29)
real(X_fin(s)'exp(jangle(f(s))))<=beta_1;

`{invalid}` most likely means the input data used there is `NaN`. Perhaps `angle(f(s)))` for at least one value of `s` is 'NaN`. If you set this input data from output of a previous optimization, it may be that that optimization did not solve to optimality, so CVX variables might have been `NaN`. Don't use `quiet` mode until you have verified everything is working correctly in your program.