找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 6851|回复: 0

[求助] 看看坛子里有没有懂CVXPY得

1

主题

1

帖子

1

积分

贫民

积分
1
wuyang0710 发表于 2018-5-26 13:50:31 | 显示全部楼层 |阅读模式
"""
Created on Tue May 22 07:46:35 2018
@author: WuYan
"""
import cvxpy as cvx
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot as plt
import matplotlib as mpl
import numpy as np
import math
#初始化
#需要初始设置的变量
V=2#最大飞行速度
Pmean=10**(-5/10)#平均功率
P_peak=4*Pmean#峰值功率
H=100#飞行高度
L=200
Startpoint = np.array([100,200,H])#无人机起点
Endpoint = np.array([100,-200,H])#无人机终点
Rpoint = np.array([0,0,H])#合法用户位置
Spoint = np.array([0,0,H])#非法用户位置
gama0=80#SNR(dB)
dt=0.5#时间间隔
#起点终点距离
Distance=np.linalg.norm(Startpoint-Endpoint)
#给定飞行时间
time=200
#向上取整得到离散点个数n
n=math.ceil(time/dt)
'''
print(Startpoint)
print(Endpoint)
print(Distance)
print(n)
'''
X0=np.linspace(Startpoint[0], Endpoint[0], n)
Y0=np.linspace(Startpoint[1], Endpoint[1], n)
P0=Pmean*np.ones(n)
U0=X0**2+Y0**2+H**2
T0=(X0-L)**2+Y0**2+H**2
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X0, Y0, H*np.ones(X0.size))
ax.scatter(0, 0, H,color='g')
ax.scatter(L, 0, H,color='R')

#可行解

Xf=X0
Yf=Y0
Uf=U0
Tf=T0
P=P0

#Ca=sum(math.log(1+gama0*P/(Xf**2+Yf**2+H**2)))
#Ce=math.log(1+gama0*P/((Xf-L)**2+Yf**2+H**2)
#test=np.log(gama0*P/(Xf**2+Yf**2))
#print('test=',test[1])
f0=np.sum(np.log(1+gama0*P/(Xf**2+Yf**2+H**2))-np.log(1+gama0*P/((Xf-L)**2+Yf**2+H**2)))

iter=1
#while iter<=200 :
    #Subproblem 2: Optimizing Trajectory For Given Transmit Power
u=cvx.Variable()
t=cvx.Variable()
x=cvx.Variable()
y=cvx.Variable()

print("U0.SIZE",U0.size)
print("U0.shape",U0.shape)
print("Uf.SIZE",Uf.size)
print("Uf.shape",Uf.shape)
print("u.size=",u.size)
test=u/(Uf**2+P*Uf)


怎么才能让u参与运算
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表