clc;
clear all;
close all;
x1=0;
x2=0;
x3=0;
x4=0;
n=10^-9; %noise
N= 16; % number of channels
h_rayleigh=(1/sqrt(2)).*(randn(N,1)+1i*randn(N,1));
h_abs= abs(h_rayleigh);
H= h_abs;
h=reshape(h_abs,4,4);
syms A [4 16] matrix
P= A*H;
i=1;
for j=1:1:4
if(j~=i)
x1= x1+h(j,i).*P(j,1);
else
x1=x1;
end
end
i=2;
for j=1:1:4
if(j~=i)
x2= x2+h(j,i).*P(j,1);
else
x2=x2;
end
end
i=3;
for j=1:1:4
if(j~=i)
x3= x3+h(j,i).*P(j,1);
else
x3=x3;
end
end
i=4;
for j=1:1:4
if(j~=i)
x4= x4+h(j,i).*P(j,1);
else
x4=x4;
end
end
X=[x1,x2,x3,x4];
size(X);
C1=log(1+(h(1,1).*P(1,1)/n+x1));
C2=log(1+(h(2,2).*P(2,1)/n+x2));
C3=log(1+(h(3,3).*P(3,1)/n+x3));
C4=log(1+(h(4,4).*P(4,1)/n+x4));
C=[C1 C2 C3 C4];
M=4;
w=linspace(0,1,M);
C_sum= C.*w;
Pimax(1:4)= 10^-4;
x0 = ones(64,1);
c_lin = [H',zeros(1,48); zeros(1,16), H',zeros(1,32);zeros(1,32),H',zeros(1,16);zeros(1,48),H'];
b = Pimax;
X = fmincon(@myfunc,x0,c_lin,b);
function C_sum1=myfunc(C_sum)
C_sum1=C_sum;
end