Illegal operation: {real affine} - {invalid}

hello,I consider my code doesn’t have problems,but it tells me the error untill all the code are entirely carried out.The strange thing is that the cvx staus is “solved”,which makes me puzzled.Also,the result that I am expected to get is not a number.2d9ea4f73bca687a306cfb40a44a3f5
the following is my code.
clear all; %#ok
close all;
clc;
%Quaratic Function Parameter
d = 1;
%agent number
n=6;

% e_abs = 1e-4;
% e_rel = 1e-4;
rho = 10;%change

MAX_ITER = 100;
X = zeros(n,n+1);
X_new = zeros(n,n+1);
lambda = zeros(n,n+1);
lambda_result1 = zeros(nMAX_ITER,n+1);
% lambda_result2 = zeros(n
MAX_ITER,n+1);
X_result = zeros(n*MAX_ITER,n+1);

% A=[0.00375,0.0175,0.0625,0.00834,0.025,0.025];

D1=[0.00375,0,0,0,0,0];
D2=[0,0.0175,0,0,0,0];
D3=[0,0,0.0625,0,0,0];
D4=[0,0,0,0.00834,0,0];
D5=[0,0,0,0,0.025,0];
D6=[0,0,0,0,0,0.025];
A1=diag(D1);
A2=diag(D2);
A3=diag(D3);
A4=diag(D4);
A5=diag(D5);
A6=diag(D6);
B1=[2,1.75,1.0,3.25,3.0,3.0;];
B2=zeros(5,6);
B=[B1;B2];
lower=[50,20,15,10,10,12];
upper=[200,80,50,35,40,40];
t = 0.5;
nu = 50;
v=100;
%senquential ADMM
for k = 1:MAX_ITER
%Agent 1
% x-update

cvx_begin
variable x_1(n)
minimize(x_1’A1x_1+B(1,:slight_smile:x_1-1/t(log(-lower(1)+x_1(1)) + log(upper(1)-x_1(1)))+ (rho/2)* sum_square_abs(X(:,7)- x_1 -1/rholambda(:,1))…
+ (rho/2)
sum_square_abs(-X(:,2)+ x_1 -1/rho*lambda(:,2)) )
cvx_end

 %lambda-update
  X_new(:,1) = x_1;
  
  lambda(:,1) = lambda(:,1) -rho*(X(:,7)-X_new(:,1));

  lambda_result1(n*(k-1)+1:n*k,1)=lambda(:,1);
  X_result(n*(k-1)+1:n*k,1)= x_1;
%Agent 2
% x-update
    cvx_begin
       variable x_2(n)
    minimize(x_2'*A2*x_2+B(2,:)*x_2-1/t*(log(-lower(2)+x_2(2)) + log(upper(2)-x_2(2))) +(rho/2)* sum_square_abs(X(:,1)- x_2 -1/rho*lambda(:,2))...
           + (rho/2)* sum_square_abs(-X(:,3)+ x_2 -1/rho*lambda(:,3)) )
    cvx_end

    
 %lambda-update
  X_new(:,2) = x_2;
  lambda(:,2) = lambda(:,2) -rho*(X(:,1)-X_new(:,2));

  lambda_result1(n*(k-1)+1:n*k,2)=lambda(:,2);
  X_result(n*(k-1)+1:n*k,2)= x_2;
  
   %Agent 3
% x-update
    cvx_begin
       variable x_3(n)
       minimize(x_3'*A3*x_3+B(3,:)*x_3-1/t*(log(-lower(3)+x_3(3))+log(upper(3)-x_3(3)))+(rho/2)* sum_square_abs(X(:,2)- x_3 -1/rho*lambda(:,3))...
           + (rho/2)* sum_square_abs(-X(:,4)+ x_3 -1/rho*lambda(:,4)) )
    cvx_end

    
 %lambda-update
  X_new(:,3) = x_3;
  lambda(:,3) = lambda(:,3) -rho*(X(:,2)-X_new(:,3));  

  lambda_result1(n*(k-1)+1:n*k,3)=lambda(:,3);
  X_result(n*(k-1)+1:n*k,3)= x_3;
  
   %Agent 4
% x-update
    cvx_begin
       variable x_4(n)
     minimize(x_4'*A4*x_4+B(4,:)*x_4-1/t*(log(-lower(4)+x_4(4)) + log(upper(4)-x_4(4)))+(rho/2)* sum_square_abs(X(:,3)- x_4 -1/rho*lambda(:,4))...
           + (rho/2)* sum_square_abs(-X(:,5)+ x_4 -1/rho*lambda(:,5)) )
    cvx_end

    
 %lambda-update
  X_new(:,4) = x_4;
  lambda(:,4) = lambda(:,4) -rho*(X(:,3)-X_new(:,4));

  lambda_result1(n*(k-1)+1:n*k,4)=lambda(:,4);
  X_result(n*(k-1)+1:n*k,4)= x_4;
  
   %Agent 5
% x-update
    cvx_begin
       variable x_5(n)
       minimize(x_5'*A5*x_5+B(5,:)*x_5-1/t*(log(-lower(5)+x_5(5)) + log(upper(5)-x_5(5)))+(rho/2)* sum_square_abs(X(:,4)- x_5 -1/rho*lambda(:,5))...
           + (rho/2)* sum_square_abs(-X(:,6)+ x_5 -1/rho*lambda(:,6)) )
    cvx_end

    
 %lambda-update
  X_new(:,5) = x_5;
  lambda(:,5) = lambda(:,5) -rho*(X(:,4)-X_new(:,5));

  lambda_result1(n*(k-1)+1:n*k,5)=lambda(:,5);
  X_result(n*(k-1)+1:n*k,5)= x_5;
  %Agent 6
% x-update
    cvx_begin
       variable x_6(n)
       minimize(x_6'*A6*x_6+B(6,:)*x_6-1/t*(log(-lower(6)+x_6(6)) + log(upper(6)-x_6(6)))+(rho/2)* sum_square_abs(X(:,5)- x_6 -1/rho*lambda(:,6))...
           + (rho/2)* sum_square_abs(-X(:,7)+ x_6 -1/rho*lambda(:,7)) )
    cvx_end
    
 %lambda-update
  X_new(:,6) = x_6;
  lambda(:,6) = lambda(:,6) -rho*(X(:,5)-X_new(:,6));

  lambda_result1(n*(k-1)+1:n*k,6)=lambda(:,6);
  X_result(n*(k-1)+1:n*k,6)= x_6;
  

%Agent 7
% x-update
    cvx_begin
       variable x_7(n)
       minimize(v*norm(x_7'*ones(n,1)-283.4)+(rho/2)* sum_square_abs(X(:,6)- x_7 -1/rho*lambda(:,7))...
           + (rho/2)* sum_square_abs(-X(:,1)+ x_7 -1/rho*lambda(:,1)) )
    cvx_end

    
 %lambda-update
  X_new(:,7) = x_7;
  lambda(:,7) = lambda(:,7) -rho*(X(:,6)-X_new(:,7));

  lambda_result1(n*(k-1)+1:n*k,7)=lambda(:,7);
  X_result(n*(k-1)+1:n*k,7)= x_7;

result(k) =x_1'*A1*x_1+B(1,:)*x_1-1/t*(log(-lower(1)+x_1(1))+log(upper(1)-x_1(1)))...
          +x_2'*A2*x_2+B(2,:)*x_2-1/t*(log(-lower(2)+x_2(2))+log(upper(2)-x_2(2)))...
          +x_3'*A3*x_3+B(3,:)*x_3-1/t*(log(-lower(3)+x_3(3))+log(upper(3)-x_3(3)))...
          +x_4'*A4*x_4+B(4,:)*x_4-1/t*(log(-lower(4)+x_4(4))+log(upper(4)-x_4(4)))...
          +x_5'*A5*x_5+B(5,:)*x_5-1/t*(log(-lower(5)+x_5(5))+log(upper(5)-x_5(5)))...
          +x_6'*A6*x_6+B(6,:)*x_6-1/t*(log(-lower(6)+x_6(6))+log(upper(6)-x_6(6)))...
          +v*norm(x_7'*ones(n,1)-283.4);

% error(k) = f - result(k);

t = nu*t;
end

please help me,I will appreciate it if you can help me.

Please show us the solver and CVX output for the last iteration for the Agent 3 CVX invocation… Add the line, disp(x3)` immediately after cvx_end for Agent 3.

Where are you getting

Illegal operation: {real affine} - {invalid}

My guess is that an NaN variable value is what is causing the “invalid”, and that the NaN is the value of a CVX variable after CVX concludes because CVX either determined that the problem ended in some status other than SolvedorInaccurate Solved`.

the solver is SDPT3.the figure is cvx output and error for the last iteration.The iteration only performs 44 ,because the error prevents further iteration. that exists a problem that x_5 and x_6 is not a number.

the figure above is not displayed completely.

Perhaps you are not showing the iteration prior to the Invalid. i am guessing that failed.

Anyhow, you should use CVX 2.2 with Mosek 9.x if you can. Otherwise, follow the directions in CVXQUAD: How to use CVXQUAD's Pade Approximant instead of CVX's unreliable Successive Approximation for GP mode, log, exp, entr, rel_entr, kl_div, log_det, det_rootn, exponential cone. CVXQUAD's Quantum (Matrix) Entropy & Matrix Log related functions

I want to ask you whether the invalid reason is because the difference of variable “t” or not.
I would like to know where my problem is.

Print print out the value of all the variables just prior to the error message. And follow my advice.

I don’t think t equal to 5e72 can be a good thing.As iterations progress, your problem data may be getting more and more extreme, beyond the ability of the solver to reliably handle. Your top level algortihm might be a piece of junk.Most crude iterative algorithms are junk.

please understand that I am the beginner of matlab.Maybe the way I use is not concise.Also,I don’t konw why you said that t equal to 5e72.the code above shows evidently t is equal to 0.5.

I read the value of t from your figure.

That value of t is apparently the result of completing the for loop 43 times.
0.5*50^43 = 5.684341886080802e+72

If you hadn’t encountered a fatal error, the last time through the for loop, t would be 0.5*50^99 = 7.8886e+167 when it would be part of the input data to your CVX program. This is a terrible, horrible, overall algorithm. I believe t will fail no matter what solver is used. When it fails, or declares the problem ot be infeasible due to horrible numerical input data, the variables will be set to NaN, which will result in the CVX error message on the next iteration.

Thank your reply patiently.I will follow your advice.

Hi,did you solve your question?can you tell me how to solve it ,maybe i met the same question as yours