# Why is this problem failed? Optimal value (cvx_optval): NaN

Here are my code.

clc; clear all;
close all;

``````m(:,1)=m_0(:,1);
gam(:,1)=gam_0(:,1);
deltat(1)=tau;
r(:,1:3)=r_0(:,1:3);
v(:,1:3)=v_0(:,1:3);
a(:,1:3)=a_0(:,1:3);
T(:,1:3)=T_0(:,1:3);
kar(:,1:3)=kar_0(:,1:3);
KAR(:,1)=KAR_0(:,1);

%%
w_t=0.1;w_T=0.00001;
n_sc=10;

for k=1:N-1
fm(k,:)=-(alpha*0.5*(gam(k,1)+gam(k+1,1))+m_bp)*deltat(1);
fr(k,:)=v(k,1:3)*deltat(1)+1/3*(a(k,1:3)+0.5*a(k+1,1:3))*(deltat(1)^2);
fv(k,:)=0.5*(a(k,1:3)+a(k+1,1:3))*deltat(1);
difft_fm(k,:)=-alpha*0.5*(gam(k,1)+gam(k+1,1))-m_bp;
diffg_fm(k,:)=-alpha*0.5*deltat(1);
difft_fr(k,:)=v(k,1:3)+2/3*(a(k,1:3)+0.5*a(k+1,1:3))*deltat(1);
diffv_fr(k,:)=deltat(1);
difft_fv(k,:)=0.5*(a(k,1:3)+a(k+1,1:3));
end
``````

for i=2:n_sc

``````cvx_begin
cvx_precision low
variables m_i(N,1) gam_i(N,1) KAR_i(N,1) etaT_i(N,1) deltat_i etat_i ;
variables r_i(N,3) v_i(N,3) a_i(N,3) T_i(N,3) kar_i(N,3);

minimize(-w_mf*m_i(N)+w_kar*norm(KAR_i(:))+w_t*etat_i+w_T*norm(etaT_i(:)));%
subject to

m_i(1)==m0;
r_i(1,:)==r0;
v_i(1,:)==v0;
T_i(1,:)==gam0*n_hat0;
gam_i(1)==gam0;
r_i(N,:)==rf;
v_i(N,:)==vf;
T_i(N,:)==gam_i(N)*n_hatf;
a_i(1,:)==1/m(1,i-1)*(T_i(1,:)-0.5*rho*sd*cd*norm(v(1,3*i-5:3*i-3))*v_i(1,:))+G;%
(deltat_i-deltat(i-1)).^2<=etat_i;

for k=1:N-1

m_i(k+1,:)==m_i(k,:)+fm(k,:)+difft_fm(k,:)*(deltat_i-deltat(i-1))+diffg_fm(k,:)*(gam_i(k)-gam(k,i-1)+gam_i(k+1)-gam(k+1,i-1));
r_i(k+1,:)==r_i(k,:)+fr(k,:)+difft_fr(k,:)*(deltat_i-deltat(i-1))+diffv_fr(k,:)*(v_i(k,:)-v(k,3*i-5:3*i-3));
v_i(k+1,:)==v_i(k,:)+fv(k,:)+difft_fv(k,:)*(deltat_i-deltat(i-1));
a_i(k+1,:)==1/m(k+1,i-1)*(T_i(k+1,:)-0.5*rho*sd*cd*norm(v(k+1,3*i-5:3*i-3))*v_i(k+1,:))+kar_i(k+1,:)+G;%

0<=deltat_i;%
m_i(k)<=m0; %
m_dry<=m_i(k);
norm(r_i(k,:))*cos(2*pi*80/360)<=r_i(k,1);
norm(T_i(k,:))<=gam_i(k);
Tmin<=gam_i(k);
gam_i(k)<=Tmax;
gam_i(k)*cos(2*pi*15/360)<=T_i(k,1);
Tmin_dot*deltat_i<=gam_i(k+1)-gam_i(k);
gam_i(k+1)-gam_i(k)<=Tmax_dot*deltat_i;
norm(kar_i(k,:))<=KAR_i(k);
(T_i(k,:)-T(k,3*i-5:3*i-3))*(T_i(k,:)-T(k,3*i-5:3*i-3))'<=etaT_i(k);%
end
norm(kar_i(k+1,:))<=KAR_i(k+1);
(T_i(k+1,:)-T(k+1,3*i-5:3*i-3))*(T_i(k+1,:)-T(k+1,3*i-5:3*i-3))'<=etaT_i(k+1);

cvx_end

%%
deltat(i)=deltat_i;
etat(i)=etat_i;

m(:,i)=m_i(:,1);
gam(:,i)=gam_i(:,1);
KAR(:,i)=KAR_i(:,1);
etaT(:,i)=etaT_i(:,1);

r(:,3*i-2:3*i)=r_i(:,1:3);
v(:,3*i-2:3*i)=v_i(:,1:3);
a(:,3*i-2:3*i)=a_i(:,1:3);
T(:,3*i-2:3*i)=T_i(:,1:3);
kar(:,3*i-2:3*i)=kar_i(:,1:3);
%%
for k=1:N-1
fm(k,:)=-(alpha*0.5*(gam_i(k,1)+gam_i(k+1,1))+m_bp)*deltat_i;%
fr(k,:)=v_i(k,1:3)*deltat_i+1/3*(a_i(k,1:3)+0.5*a_i(k+1,1:3))*(deltat_i^2);%
fv(k,:)=0.5*(a_i(k,1:3)+a_i(k+1,1:3))*deltat_i;%
difft_fm(k,:)=-alpha*0.5*(gam_i(k,1)+gam_i(k+1,1))-m_bp;%
diffg_fm(k,:)=-alpha*0.5*deltat_i;%
difft_fr(k,:)=v_i(k,1:3)+2/3*(a_i(k,1:3)+0.5*a_i(k+1,1:3))*deltat_i;%
diffv_fr(k,:)=deltat_i;%
difft_fv(k,:)=0.5*(a_i(k,1:3)+a_i(k+1,1:3));%
end
``````

## Calling SDPT3 4.0: 961 variables, 569 equality constraints

num. of constraints = 569
dim. of sdp var = 2, num. of sdp blk = 1
dim. of socp var = 583, num. of socp blk = 124
dim. of linear var = 362
dim. of free var = 13 *** convert ublk to lblk

SDPT3: Infeasible path-following algorithms

## number of iterations = 25 primal objective value = -1.38632312e+04 dual objective value = -1.35943176e+04 gap := trace(XZ) = 5.98e+02 relative gap = 2.18e-02 actual relative gap = -9.79e-03 rel. primal infeas (scaled problem) = 1.47e-10 rel. dual " " " = 2.23e-10 rel. primal infeas (unscaled problem) = 0.00e+00 rel. dual " " " = 0.00e+00 norm(X), norm(y), norm(Z) = 1.8e+07, 3.5e+08, 7.4e+06 norm(A), norm(b), norm© = 5.5e+05, 1.5e+06, 5.0e+05 Total CPU time (secs) = 3.38 CPU time per iteration = 0.14 termination code = -7 DIMACS: 9.1e-10 0.0e+00 2.2e-10 0.0e+00 -9.8e-03 2.2e-02

Status: Failed
Optimal value (cvx_optval): NaN

Perhaps the scaling of the input data is bad.

Thank you, Mark. The input data is calculated as follows. It contains all the status of a reference trajectory.

clc; clear all;
close all;

%%
Pamb=100e3;%
A =0.5;%
Isp=300;%
g=9.807;%
rho=1;%
sd=10;%
cd=1;%
N=31; %
tf=15;%
tau=tf/(N-1);%

%%
alpha=1/(Ispg);%
m_bp=Pamb
A*alpha;%
G=[-g,0,0];
Tmin=100e3; Tmax=250e3;%
Tmin_dot=-100e3;Tmax_dot=100e3;%

m0=15000; m_dry=10000;%
r0=[500,500,0]; v0=[-50,0,50]; %
n_hat0=[1,0,0];gam0=175e3;%
rf=[0,0,0]; vf=[0,0,0];n_hatf=[1,0,0]; %
w_mf=1;w_kar=5e5;
u(1)=m0;
s(1)=norm(v0);
for i=1:N
u(i)= m0-(m0-m_dry)(i-1)/(N-1);%
s(i)= norm(v0)
(1-(i-1)/(N-1));%
end

cvx_begin
%%
cvx_precision high
variables m_0(N,1) gam_0(N,1) KAR_0(N,1);%
variables r_0(N,3) v_0(N,3) a_0(N,3) T_0(N,3) kar_0(N,3);%

%%

minimize(-w_mfm_0(N)+w_karnorm(KAR_0));

%%
subject to
m_0(1)==m0;
gam_0(1)==gam0;
r_0(1,:)==r0;
v_0(1,:)==v0;
T_0(1,:)==gam0n_hat0;
r_0(N,:)==rf;
v_0(N,:)==vf;
T_0(N,:)==gam_0(N)n_hatf;
kar_0(1,:)==[0,0,0];
a_0(1,:)==1/u(1)
(T_0(1,:)-0.5
rhosdcd*s(1)*v_0(1,:))+G;%

``````for k =1:N-1   %
m_0(k+1)==m_0(k)-(alpha*0.5*(gam_0(k)+gam_0(k+1))+m_bp)*tau;%
r_0(k+1,:)==r_0(k,:)+v_0(k,:)*tau+1/3*(a_0(k,:)+0.5*a_0(k+1,:))*(tau^2);%
v_0(k+1,:)==v_0(k,:)+0.5*(a_0(k,:)+a_0(k+1,:))*tau;
a_0(k+1,:)==1/u(k+1)*(T_0(k+1,:)-0.5*rho*sd*cd*s(k)*v_0(k+1,:))+kar_0(k+1,:)+G;

m_dry<=m_0(k);
norm(r_0(k,:))*cos(2*pi*80/360)<=r_0(k,1);
norm(T_0(k,:))<=gam_0(k);
Tmin<=gam_0(k);
gam_0(k)<=Tmax;
gam_0(k)*cos(2*pi*15/360)<=T_0(k,1);
Tmin_dot*tau<=gam_0(k+1)-gam_0(k);
gam_0(k+1)-gam_0(k)<=Tmax_dot*tau;
norm(kar_0(k,:))<=KAR_0(k);
end
``````

cvx_end
save(‘gamma0’);

There are some rather large input values. That may contribute to solver difficulties. To to change units to improve the scaling. You can also try a different solver.

I’ll try now. Thank you very much.

It works after I change the units, the first iteration can be solved. But I meet a new question in the next iteration.

## Calling SDPT3 4.0: 900 variables, 508 equality constraints

num. of constraints = 508
dim. of sdp var = 2, num. of sdp blk = 1
dim. of socp var = 583, num. of socp blk = 124
dim. of linear var = 302
dim. of free var = 12 *** convert ublk to lblk

SDPT3: Infeasible path-following algorithms

## number of iterations = 26 primal objective value = -4.04651368e+03 dual objective value = -4.04651741e+03 gap := trace(XZ) = 6.44e-03 relative gap = 7.96e-07 actual relative gap = 4.62e-07 rel. primal infeas (scaled problem) = 9.13e-11 rel. dual " " " = 1.38e-10 rel. primal infeas (unscaled problem) = 0.00e+00 rel. dual " " " = 0.00e+00 norm(X), norm(y), norm(Z) = 5.8e+03, 6.2e+05, 1.0e+06 norm(A), norm(b), norm© = 6.1e+02, 2.0e+03, 5.0e+05 Total CPU time (secs) = 3.48 CPU time per iteration = 0.13 termination code = 0 DIMACS: 3.6e-10 0.0e+00 1.4e-10 0.0e+00 4.6e-07 8.0e-07

Status: Solved
Optimal value (cvx_optval): -14025.3

## Calling SDPT3 4.0: 891 variables, 499 equality constraints

num. of constraints = 499
dim. of sdp var = 2, num. of sdp blk = 1
dim. of socp var = 583, num. of socp blk = 124
dim. of linear var = 302
dim. of free var = 3 *** convert ublk to lblk

SDPT3: Infeasible path-following algorithms

## 0|0.000|0.000|9.0e+01|1.1e+01|5.9e+10| 1.198677e+09 0.000000e+00| 0:0:00| chol 2 2 1|0.853|0.830|1.3e+01|1.9e+00|1.1e+10| 1.973010e+08 4.195316e+08| 0:0:00| chol warning: symqmr failed: 0.3 switch to LU factor. lu 23 9 2|0.463|0.330|7.1e+00|1.3e+00|7.4e+09| 1.139475e+08 1.033089e+12| 0:0:01| lu 15 30 3|0.281|0.140|4.8e+00|1.1e+00|6.4e+09| 9.742562e+07 -1.093926e+15| 0:0:01| lu 11 ^ 6 4|0.206|0.457|3.9e+00|5.9e-01|4.9e+09| 8.479296e+07 4.162216e+14| 0:0:01| lu 18 ^ 2 5|0.227|0.037|3.2e+00|5.7e-01|4.3e+09| 7.201615e+07 8.060362e+14| 0:0:01| lu 30 ^19 6|0.460|0.087|1.9e+00|5.2e-01|3.5e+09| 5.520987e+07 1.131825e+15| 0:0:01| lu 12 30 7|0.734|0.608|6.5e-01|2.0e-01|1.4e+09| 3.241025e+07 6.216765e+14| 0:0:01| lu 30 ^29 8|0.065|0.429|6.1e-01|1.2e-01|1.2e+09| 3.225109e+07 -2.172194e+14| 0:0:01| lu 30 ^14 9|0.272|0.235|4.4e-01|8.9e-02|9.1e+08| 3.167535e+07 -3.027374e+14| 0:0:02| lu 12 ^30 10|0.580|0.096|2.6e-01|8.0e-02|6.9e+08| 2.759204e+07 -3.088615e+14| 0:0:02| lu 16 ^16 11|0.211|0.159|4.1e-01|6.7e-02|5.6e+08| 2.447285e+07 -7.160947e+13| 0:0:02| lu 13 ^ 2 12|0.078|0.020|3.7e-01|6.6e-02|6.0e+08| 2.467467e+07 -6.644534e+13| 0:0:02| lu 30 ^16 13|0.112|0.036|4.4e-01|6.4e-02|6.3e+08| 2.534561e+07 -7.726766e+13| 0:0:02| lu 18 ^13 14|0.312|0.032|2.2e-01|6.2e-02|5.7e+08| 2.500949e+07 -1.010807e+14| 0:0:02| lu 22 30 15|0.000|0.000|2.2e-01|6.2e-02|5.8e+08| 2.501113e+07 -1.014609e+14| 0:0:03| lu 18 30 16|0.001|0.002|2.2e-01|6.1e-02|6.5e+08| 2.502084e+07 -1.059026e+14| 0:0:03| lu 18 30 17|0.009|0.022|2.2e-01|6.0e-02|6.1e+08| 2.513063e+07 -1.314018e+14| 0:0:03| lu 12 ^ 9 18|0.005|0.006|4.2e-01|6.0e-02|6.0e+08| 2.515437e+07 1.500114e+14| 0:0:03| lu 11 ^22 19|0.080|0.174|9.0e-01|4.9e-02|5.4e+08| 2.488939e+07 1.068346e+15| 0:0:03| lu 11 30 20|0.016|0.054|9.0e-01|4.7e-02|5.2e+08| 2.490768e+07 1.592379e+15| 0:0:04| lu 11 ^30 21|0.005|0.002|8.8e-01|4.7e-02|5.2e+08| 2.486601e+07 1.569167e+15| 0:0:04| stop: progress is too slow prim_inf,dual_inf,relgap = 8.79e-01, 4.66e-02, 3.33e-07 sqlp stop: primal problem is suspected of being infeasible

number of iterations = 21
residual of primal infeasibility
certificate (y,Z) = -4.73e-09
reldist to infeas. <= 9.22e-11
Total CPU time (secs) = 3.99
CPU time per iteration = 0.19
termination code = 1
DIMACS: 8.5e-01 0.0e+00 6.1e-02 0.0e+00 1.0e+00 6.2e-06

Unsafeguarded (no line search or trust region) Successive Convex Approximation is rather unreliable and can be unstable. If you have a non-convex problem, you may be better off using a non-convex solver, available, for instance, under YALMIP.

Thank you, Mark. Actually, I have added an additive relaxation term, kar(i). But it seems that it didn’t work in the 2nd iteration.