CVXPY: how to use "log"

import cvxpy as cvx
import node
import math
import numpy as np
X = cvx.Variable()
Y = cvx.Variable()


for i in range(100):
x =node.all_points[i][0]
y =node.all_points[i][1]
dis_pow =(np.square(X-x)+np.square(Y-y)+np.square(100))
sum= sum + r

constraints= [X >= 0,X <= 100,Y >= 0,Y <= 100]
obj = cvx.Maximize(sum)

prob = cvx.Problem(obj, constraints)
print(“status:”, prob.status)
print(“optimal value”, prob.value )
print(“optimal var”, X.value, Y.value)

This is my code,log2(m) in python must be real number, not AddExpression. node.all_points is a matrix of 100 points(location). I don’t know how to solve this problem.


CVXPY is a different tool than CVX. Support questions for it can be asked at!forum/cvxpy .

Thank you for your reply,and I want to know whether is question can be solved by CVX?

The objective function is not concave, so the problem is not convex, so not solvable by CVX. Actually, I believe the objective function is convex over the domain in your constraints.

If it can be handled by CVXPY at all, it would not be in the DCP mode. Perhaps it can be handled (with no assurance of finding global optimum) by DCCP, but that is out of scope of CVX and the CVX forum.

Please read
Why isn't CVX accepting my model? READ THIS FIRST! .

That will help you for CVX and CVXPY, although CVXPY does have some additoonal capabilities which CVX does not, such as DCCP.

1 Like

Thank you again. How can I improve this objective function to follow the DCP rule in this question?
Find a location (X,Y, 100) that maximizes the sum of the UAV’s transmission rates to the 100 nodes on the ground.

It’s up to you to formulate a convex optimization problem. If your problem is non-convex, I recommend you use a non-convex solver, which can not be done from CVX.