# 分式规划和波束成形（MATLAB代码）




# Dinkelbach_type_algorthm





q1=20
q2=30
q3=35
q4=28
N=4
m=4
k=1

h=abs(rand(N,m+2))
g=abs(rand(N,m+2))
v=abs(randn(N,1,k))
x=abs(randn(N,m,k))
t2=1
while t2~=0
for i=1:m
temp0=0
for j=1:m
if i==j
continue
else
s=temp0+h(:,i)'*x(:,j,k)*x(:,j,k)'*h(:,i)
temp0=s
end
end
u(i)=(-h(:,i)'*x(:,i,k)*x(:,i,k)'*h(:,i))/(s+g(:,i)'*v(:,:,k)*v(:,:,k)'*g(:,i))
end
u_value(k)=max(u)

cvx_begin sdp
variable W(N,N,m+1) complex hermitian
variable V(N,N) complex hermitian
variable t
minimize t;
subject to;

temp1=0
for i=1:m+1
s1=trace(W(:,:,i))+temp1
temp1=s1
W(:,:,i) == hermitian_semidefinite(N)
end
temp1<=q1                        %信息发射端的功率小于q1
trace(V(:,:))<=q2
V  == hermitian_semidefinite(N) %是半定矩阵

temp2=0
for i=1:m+1
s2= trace( h(:,4)'*W(:,:,i)*h(:,4))+temp2
temp2=s2
end
temp2+trace(g(:,4)'*V(:,:)*g(:,4))>=q3

temp3=0
for i=1:m+1
s3=  trace(h(:,5)'*W(:,:,i)*h(:,5))+temp3
temp3=s3
end
temp3+trace(g(:,5)'*V(:,:)*g(:,5))<=q4

for i=1:m

temp5=0
for j=1:m
if i==j
continue
else

s2=-h(:,i)'*W(:,:,j)*h(:,i)+temp5
temp5=s2
end
end
trace(s2*u_value(k))-trace(h(:,i)'*W(:,:,i)*h(:,i))-trace(g(:,i)'*V(:,:)*g(:,i)*u_value(k))<=t
end
cvx_end
mine(k)=cvx_optval
k=k+1
for i=1:m
for j=1:N
a(j)=sqrt(W(j,j,i))
end
b(:,i)=a'
end
x(:,:,k)=b
for i=1:N
c(i)=sqrt(V(i,i))
end
v(:,:,k)=c'

t2(k-1)=-cvx_optval
if k<=18
continue
else
break
end

end


Dinkelbach_type_2algorthm

q1=20
q2=30
q3=35
q4=28
N=4
m=4
k=1

h=abs(rand(N,m+2))
g=abs(rand(N,m+2))
v=abs(randn(N,1,k))
x=abs(randn(N,m,k))
t2=1
while t2~=0
for i=1:m
temp0=0
for j=1:m
if i==j
continue
else
s=temp0+h(:,i)'*x(:,j,k)*x(:,j,k)'*h(:,i)
temp0=s
end
end
u(i)=(-h(:,i)'*x(:,i,k)*x(:,i,k)'*h(:,i))/(s+g(:,i)'*v(:,:,k)*v(:,:,k)'*g(:,i))
end
u_value(k)=max(u)

cvx_begin sdp
variable W(N,N,m+1) complex hermitian
variable V(N,N) complex hermitian
variable t
minimize t;
subject to;

temp1=0
for i=1:m+1
s1=trace(W(:,:,i))+temp1
temp1=s1
W(:,:,i) == hermitian_semidefinite(N)
end
temp1<=q1                        %信息发射端的功率小于q1
trace(V(:,:))<=q2
V  == hermitian_semidefinite(N) %是半定矩阵

temp2=0
for i=1:m+1
s2= trace( h(:,4)'*W(:,:,i)*h(:,4))+temp2
temp2=s2
end
temp2+trace(g(:,4)'*V(:,:)*g(:,4))>=q3

temp3=0
for i=1:m+1
s3=  trace(h(:,5)'*W(:,:,i)*h(:,5))+temp3
temp3=s3
end
temp3+trace(g(:,5)'*V(:,:)*g(:,5))<=q4

for i=1:m
temp4=0
temp5=0
for j=1:m
if i==j
continue
else
s1=temp4+h(:,i)'*x(:,j,k)*x(:,j,k)'*h(:,i)
temp4=s1
s2=-h(:,i)'*W(:,:,j)*h(:,i)+temp5
temp5=s2
end
end
trace(s2*u_value(k))-trace(h(:,i)'*W(:,:,i)*h(:,i))-trace(g(:,i)'*V(:,:)*g(:,i)*u_value(k))<=trace((s1+g(:,i)'*v(:,:,k)*v(:,:,k)'*g(:,i)))*t
end
cvx_end
mine(k)=cvx_optval
k=k+1
for i=1:m
for j=1:N
a(j)=sqrt(W(j,j,i))
end
b(:,i)=a'
end
x(:,:,k)=b
for i=1:N
c(i)=sqrt(V(i,i))
end
v(:,:,k)=c'

t2(k-1)=-cvx_optval
if k<=18
continue
else
break
end

end