# Need help to reformulate Projectile Motion to a convex problem

I will try to formulate my question precise as possible. I am aware of there’s a introduction to cvx pdf and a thread about what not to do in CVX. I tried to look in them and see if I could find the answer there before making this new topic.

My question is as follows:

I am trying to solve a simple problem just to try the CVX toolbox. The problem is about “Projectile motion” and the formulas can be seen on this wikipedia page: https://en.wikipedia.org/wiki/Projectile_motion

My idea is that I want to maximize the distance the ball can fly (xmax = vx * vy * 2/ g) and put one constraint so the ball does not go above some fixed height (ymax = vy^2/2*g).

``````g = 9.82;
cvx_begin
variables vx vy
maximize vx * vy * 2/ g
subject to
vy^2/2*g <= 5;
cvx_end
``````

The problem with this expression is that I am not allowed to multiply two variables with each other since they are not always convex. I found others having the same problem but I haven’t found the solution in theirs topic. I also tried to add constraints for vx > 0 and vy > 0 but that did not help. When I change vx to a fixed value the following problem can be solved… But why?

``````g = 9.82; vx = 10;
cvx_begin
variables vy
maximize vx * vy * 2/ g
subject to
vy^2/2*g <= 5;
cvx_end
``````

I would really like to get some tips about how to fix it so it can work with CVX.

Thanks in regards.

I have no idea what your formula
`vx * vy * 2/ g`
i s supposed to be. What is that the maximum distance of? I certainly don’t see such a formula anywhere in the Wikipedia article you linked.

`vx * vy * 2/ g` is neither a convex nor concave function of `vx` and `vy`. If `vx` is fixed at a particular value, such as 10, rather than being a CVX variable, then `vx * vy * 2/ g` is an affine function of `vy.` As such, CVX will allow you to use it in an objective function to be maximized or minimized, or on the Left Hand Side or Right Hand Side of an equality or inequality constraint.

As I wrote in my first post, I don’t see such a formula there. The product term `vx*vy` doesn’t make any sense in this application. You can get a term proportional to the square of the initial speed; that is a function of one variable, not the product of two variables.