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.