The cvx_optval unequal to the object value

hello, I meet one problem when using the CVX toolbox. The cvx_optval unequal to the object value which is using the value of the optimization variable obtained by CVX.
My matlab code is as follows:

image

clc
clear
N=20;
T_bar=20;
dt=1/N;
q0=[0;0;20];
qf=[20;20;40];
w=[15;5;0];
H_min=10;
c0=0.036;
c1=0.0075;
c2=8.5938 * 1e-6;
c3=8.8949 * 1e-7;
c4=5.1287 * 1e-10;
Pc=5;
u_max=640;
u_min=350;
delta=[5;5;5;10;10;10;0.5;0.5;0.5;0.5;0.5;0.5];
x0=[q0;1;1;1;0;0;0;0;0;0];
x_bar=zeros(12,N);
u_bar=zeros(4,N-1);
u_bar(:,:)=500;
V0=1;
Vmax=2;
x_bar(:,1)=x0;
for n=1:N-1
x_bar(1:3,n+1)=x_bar(1:3,n)+V0 * T_bar * dt;
end
x_bar(4:6,2:N)=V0T_bardt;
%communication condition
Qk=50;
gamma=1e5;
E_cur=2fun_E(u_bar,T_bardt);
m=0;
Ju=zeros(1,4*(N-1));
dist=(x_bar(1,1:end-1)-w(1)).^2+(x_bar(2,1:end-1)-w(2)).^2+(x_bar(3,1:end-1)-w(3)).^2;
Alpha=log2(1+gamma./dist);
Beta=log2(exp(1))gamma./((dist+gamma) . * dist);
A_cur=sqrt(T_bar
dtAlpha);
for n=1:N-1
Ju(1,4
n-3:4n)=fun_dJdu(u_bar(:,n),T_bardt);
end
P_bar=fun_dJdt(u_bar,dt);
cvx_clear
cvx_begin
cvx_quiet(true);
variable u(4,N-1)
variable x(12,N)
variable A_bar(1,N-1)
variable T
minimize (T_bardt(sum(sum(c4pow_abs(u,4)+c3pow_abs(u,3)+c2pow_abs(u,2)+c1u+c0))))
subject to
T>=5;
T<=40;
abs(T-T_bar)<=5;
u<=u_max;
u>=u_min;
abs(u(2,:)-u(4,:))<=5;
abs(u(1,:)-u(3,:))<=5;
x(:,1)==x0;
for n=1:N-1
f_bar=UAV_func(x_bar(:,n),u_bar(:,n),T_bar,dt);
A=UAV_dfdx(x_bar(:,n),u_bar(:,n),T_bar,dt);
B=UAV_dfdu(x_bar(:,n),u_bar(:,n),T_bar,dt);
C=UAV_dfdz(x_bar(:,n),u_bar(:,n),T_bar,dt);
abs(x(:,n)-x_bar(:,n))<=deltaT_bardt;
x(:,n+1)==x(:,n)+f_bar+A*(x(:,n)-x_bar(:,n))+B*(u(:,n)-u_bar(:,n))+…
C*(T-T_bar);
x(3,n)>=H_min;
end
for n=1:N-1
quad_over_lin(A_bar(n),Tdt)<=Alpha(n)-Beta(n)(pow_pos(norm(x(1:3,n)-w),2)-dist(n));
end
sum(A_cur.^2+2A_cur.(A_bar-A_cur))>=Qk;
x(1:3,N)==qf;
cvx_end
cvx_optval
obj=(T_bardt(sum(sum(c4pow_abs(u,4)+c3pow_abs(u,3)+c2pow_abs(u,2)+c1u+c0))))
%the cvx_optval unequal to obj. Why?

%%%%%%%Best wish you can help me!

This is not reproducible because you have not provided the value of V0T_bardt.

having such extreme numbers as c2=8.5938 * 1e-6;
c3=8.8949 * 1e-7;
c4=5.1287 * 1e-10;
is generally not a good idea, and can cause numerical difficulties or unreliability in the solution. You should try to re-scale your problem by changing units so that all input data us closer to one in magnitude.

You should not use cvx_quiet(true) until you are sure your program is working correctly. Remove that and re-run it. Then you will see the solver and CVX output. Show us that, together with your own calculation showing whart you claim.

Thank you, Mark. I’ve found that the reason is an order of magnitude difference. I solved this problem by adjusting c2, c3, c4.