cvxpy how to deal with "log"

310 views
Skip to first unread message

Pauline Saddler

unread,
Jun 28, 2020, 8:49:36 AM6/28/20
to cvxpy

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

sum=0

for i in range(100):
x =node.all_points[i][0]
y =node.all_points[i][1]
w=[x,y]
dis_pow =(np.square(X-x)+np.square(Y-y)+np.square(100))
r=math.log2(1+pow(10,8)/dis_pow)
sum= sum + r

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

prob = cvx.Problem(obj, constraints)
prob.solve()
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.

Thanks.

Steven Diamond

unread,
Jun 28, 2020, 2:28:12 PM6/28/20
to cvxpy
You cannot use math or numpy functions on cvxpy objects. You can only use cvxpy functions on cvxpy objects.

Pauline Saddler

unread,
Jun 28, 2020, 9:29:59 PM6/28/20
to cvxpy
Thank you for your reply,I used cvx.log as you said,but the objective is not DCP,How can I solve this problem, or improve this expression to follow DCP rules?

Pauline Saddler

unread,
Jun 28, 2020, 9:31:23 PM6/28/20
to cvxpy

Steven Diamond

unread,
Jul 18, 2020, 3:01:24 PM7/18/20
to cvxpy
Why don't you try our new cvxpy analyzer? It will debug your problem: https://github.com/cvxgrp/cvxpyanalyzer
Reply all
Reply to author
Forward
0 new messages