I have only recently come into contact with cvx and am eager to use it to complete the trajectory optimization of aircraft. Therefore, my convex optimization theory is relatively weak and it is difficult to find problems in the program. I have the following error in use:
Error using * (line 306)
Disciplined convex programming error:
This expression produced one or more invalid numeric values (NaNs).
Error in \ (line 14)
z = mtimes( x, y, ‘ldivide’ );
Error in slack_inturn (line 133)
X(:,i) = Ak-(Bk*(t0-tf)U1(:,1) + (Tk-BkU1k(:,i))U2 + Wk + 2DX(:,i));
My code is here.
cvx_begin
cvx_solver mosek
variable U1(3,n); %u1 u2 u3
variable U2(1,1); %tf
expression X(6,n+1);
expression AX(6,1);
expression DX(n,6);
obj = U2;
minimize(obj);
subject to
X(:,1)== X0;
X = X';
for num_x = 1:NX
DX(:,num_x) = D*X(:,num_x);
end
DX = DX’;
X = X’;
for i=1:n
Ak = [ - (R0*S*V(i)*cdjian*rou0*exp(-R0*beta*y(i)))/(2*m) - (R0*S*V(i)*cdjian*rou0*u3(i)*exp(-R0*beta*y(i)))/(2*m), -cos(theta(i))/r(i)^2, 0, 0, (R0^2*S*V(i)^2*beta*cdjian*rou0*exp(-R0*beta*y(i)))/(4*m) + (R0^2*S*V(i)^2*beta*cdjian*rou0*u3(i)*exp(-R0*beta*y(i)))/(4*m), 0;
cos(theta(i))/(V(i)^2*r(i)^2) + (R0*S*cljian*rou0*u1(i)*exp(-R0*beta*y(i)))/(2*m), sin(theta(i))/(V(i)*r(i)^2), 0, 0, -(R0^2*S*V(i)*beta*cljian*rou0*u1(i)*exp(-R0*beta*y(i)))/(2*m), 0;
-(R0*S*cljian*rou0*u2(i)*exp(-R0*beta*y(i)))/(2*m*cos(theta(i))), -(R0*S*V(i)*cljian*rou0*u2(i)*exp(-R0*beta*y(i))*sin(theta(i)))/(2*m*cos(theta(i))^2), 0, 0, (R0^2*S*V(i)*beta*cljian*rou0*u2(i)*exp(-R0*beta*y(i)))/(2*m*cos(theta(i))), 0;
cos(psi(i))*cos(theta(i)), -V(i)*cos(psi(i))*sin(theta(i)), -V(i)*cos(theta(i))*sin(psi(i)), 0, 0, 0;
sin(theta(i)), V(i)*cos(theta(i)), 0, 0, 0, 0;
-cos(theta(i))*sin(psi(i)), V(i)*sin(psi(i))*sin(theta(i)), -V(i)*cos(psi(i))*cos(theta(i)), 0, 0, 0];
Bk = [ 0, 0, -(R0*S*V(i)^2*cdjian*rou0*exp(-R0*beta*y(i)))/(4*m);
(R0*S*V(i)*cljian*rou0*exp(-R0*beta*y(i)))/(2*m), 0, 0;
0, -(R0*S*V(i)*cljian*rou0*exp(-R0*beta*y(i)))/(2*m*cos(theta(i))), 0;
0, 0, 0;
0, 0, 0;
0, 0, 0];
Tk = -1*[-0.5*0.5*R0*rou0*exp(-beta*R0*y(i))*V(i)*V(i)*S*cdjian/m-sin(theta(i))/(r(i)*r(i))-0.5*0.5*R0*rou0*exp(-beta*R0*y(i))*V(i)*V(i)*S*cdjian*u3(i)/m;
-cos(theta(i))/(V(i)*r(i)*r(i))+u1(i)*0.5*R0*rou0*exp(-beta*R0*y(i))*V(i)*V(i)*S*cljian/(m*V(i));
-u2(i)*0.5*R0*rou0*exp(-beta*R0*y(i))*V(i)*V(i)*S*cljian/(m*V(i)*cos(theta(i)));
V(i)*cos(theta(i))*cos(psi(i));
V(i)*sin(theta(i));
-V(i)*cos(theta(i))*sin(psi(i))];
fk = [-0.5*0.5*R0*rou0*exp(-beta*R0*y(i))*V(i)*V(i)*S*cdjian/m-sin(theta(i))/(r(i)*r(i))-0.5*0.5*R0*rou0*exp(-beta*R0*y(i))*V(i)*V(i)*S*cdjian*u3(i)/m;
-cos(theta(i))/(V(i)*r(i)*r(i))+u1(i)*0.5*R0*rou0*exp(-beta*R0*y(i))*V(i)*V(i)*S*cljian/(m*V(i));
-u2(i)*0.5*R0*rou0*exp(-beta*R0*y(i))*V(i)*V(i)*S*cljian/(m*V(i)*cos(theta(i)));
V(i)*cos(theta(i))*cos(psi(i));
V(i)*sin(theta(i));
-V(i)*cos(theta(i))*sin(psi(i))];
Xk = [V;theta;psi;x;y;z];
U1k = [u1(1:n);u2(1:n);u3(1:n)];
Wk = (t0-tf)*fk + (t0-tf)*Bk*U1k(:,i) - Ak*Xk(:,i) - Tk*tf - (t0-tf)*Bk*U1k(:,i) + Bk*U1k(:,i)*tf;
X(:,i) = Ak\-(Bk*(t0-tf)*U1(:,1) + (Tk-Bk*U1k(:,i))*U2 + Wk + 2*DX(:,i));
end
cvx_end
Please tell me where the error is and how I should modify the program. I will be very grateful for your guidance.