How do I optimize a variable and its derivative on CVX?

(Seifeldeen Hesham) #1

I’m trying to do some trajectory optimization for a UAV, and it’s been successful when assuming that velocity would be constant. However now, I’m trying to set velocity as a variable, and hence make the problem more real-life like by also maximizing and minimizing its acceleration.

Here’s just a part of the code:

for T = [100 101 105 120 160];
cvx_begin quiet
variable x(T) complex
variable V(T) complex
variable a(T) complex
V = (x(T)-x(T-1))/(T-(T-1)) %not really a condition
norm(x(1) - x0) <= V;

        for t = 2:T
            norm(x(t)-x(t-1)) <= V;
            norm(x(t) - xH) <= V*(T-t);
            a = (V(t)-V(t-1))/(t-(t-1));

Later, I want to maximize and minimize the acceleration at specific position ranges, however, CVX says this (below) once I introduce “a” as the derivative of V
(Index exceeds array bounds.)

I would really appreciate any help :slight_smile:

(Mark L. Stone) #2

V is a scalar, which is not what you want. I think you need to move the calculation of V into the (a) for loop. And then you will need to chop off one more value of t (start at = 3) for the calculation of a in order to keep the double differencing within bounds.

a should be declared as an expression, not as a variable. Read to see how to properly handle an expression vector.

In general, you need to make sure your code runs in MATLAB without any dimension, index, non-conformal, etc. errors presuming that all CVX variables are replaced with the same dimensioned numerically populated variables. That is a matter of MATLAB syntax, not really CVX. Once that executed without error, simply insert the variables declarations, and then the indexing, dimensions, etc. should be correct in CVX.

Do you really want the variables to be complex? I suspect not. As it is now, your inequalities will not be accepted by CVX because the right-hand sides are complex.

1 Like
(Seifeldeen Hesham) #3

Thank you for your reply!

I seem to still have a persistent issue with my code. Would you be free to talk briefly maybe over Skype where you could see my code?

Thanks a lot in advance! :slight_smile:

(Mark L. Stone) #4

All communication for this forum is handled by forum posts.

(Seifeldeen Hesham) #5

I understand.
How do I declare “a” as an expression not a variable? I moved V into the for loop, yet I’m still getting the same error

(Mark L. Stone) #6

See the link I provided previously

You will probably benefit from a careful re-reading of the entire CVX Users’ Guide now that you have some experience.