Sorry for the question which is not exactly related to CVX but I’m trying to use CVX to solve a problem that has a constraint that contains the function tan(theta2-theta1) where both angles are unknowns. Is there a way to convexify such function?

# Convexification of Tan(x)

**Mark_L_Stone**(Mark L. Stone) #2

The one term Taylor expansion, which is the linear approximation, `theta2 -theta1`

can be used, but will only be “valid” (good) for small (whatever that is) values of |theta2 - theta1|. That might be a lousy approximation for use in an optimization problem. You could do successive convex approximation (in this case linearizartion) by using CVX to solve subproblems in which the linearization is performed around the optimal value from the preceding CVX subproblem (and using an initial value before the first subproblem) - there are no guarantees it will converge to anything, let alone a global or even local optimum of the original problem.

Unless abs(theta2 - theta1) is constrained to be small, you are probably better of using a non-convex nonlinear optimizer, which is designed to handle such problems.

**Mark_L_Stone**(Mark L. Stone) #4

If you construct a convex hull which is consistent with CVX’s rules, then you can implement it in CVX. Whether that convex hull proves useful toward adequately and accurately enough solving your original problem is another matter.

In principle you can construct a better approximation than linear approximation by using a piecewise linear approximation using binary variables. So something similar to http://homepages.rpi.edu/~mitchj/handouts/piecewise/ or http://winglpk.sourceforge.net/media/glpk-sos2_02.pdf , which can be implemented in CVX using binary variables (MIDCP).

I think you are better off following my original advice to use a non-convex nonlinear optimizer, which is designed to handle such problems.

**Deek**#5

Thanks a lot. One last question. If I have the function x.tan(theta2-theta1) where x is a continuous variable. Is there any way of convexifying such expression?

**Mark_L_Stone**(Mark L. Stone) #6

Only in the most tortured way using approximate binary expansions of the continuous variables and then linearizing the product terms. So practically speaking, no.