# I want write this formula in CVX matlab

and h=(1/sqrt(2))(randn+i+randn)
(h is Coefficient channel)
i wrote false code
in_snr=6;
h=(1/sqrt(2))
(randn+i+randn);
cvx_begin
variable p(k)
variable teta(k)

minimize p(k)
minimize teta(k)
subject to
for k=1:2;
for j=1:2;

``````      a=a+(p(j)*abs(h(j,k))^2);
``````

-((1/in_snr)+1)*(p(k)*abs(h(k,k))^2)+a-90+(-60/teta(k))<=0;
(6/(1-teta(k)))-(a-90)<=0
0<teta(k)<1
p(k)>0
end
end
cvx_end

Minimizing with respect to p and theta means that they should be declared CVX variables as you have done. However, that doesn’t mean that either is necessarily the objective function, and certainly not both, as you have done. Your objective function statement should be `minimize(sum(p))`

You will need to use `inv_pos` for the last term on the left-hand side of (5b) and the first term in (5c).

Note that all inequalities in CVX are treated as non-strict. So if you need strict inequalities, you will need to add your own offset amount, such as `1e-6 <= theta <= 1-1e-6` and `p >= 1e-6`.

The statement ` a=a+(p(j)*abs(h(j,k))^2);` keeps on accumulating over all `j` and `k`, which is not what you want,. I will let you fix the constraints. Your guiding principle should be that if instead of declaring `p` and teta` to be CVX variables, they were just regular numerically populated MATLAB vectors, the left-hand sides of the constraints should evaluate to the correct value. Once that is done, merely declare the variables rather than numerically populating them, and your code should be correct, presuming the code follows all CVX rules.

tnx dear
can you help me about my code? (sigma and sum in formoula)
and i have 2 optimization

1. minimize Pk
2. minimiza teta k

and
i have this error:
Undefined function or variable ‘inv_po’.
my code is:
in_snr=6;
e=6;
h=(1/sqrt(2))*(randn+i+randn);
cvx_begin
variable p(k)
variable teta(k)

minimize(sum§)
% minimize teta(k)
subject to
for k=1:2;
for j=1:2;
a=0
a=a+(p(j)abs(h(j,k))^2);
inv_po -((1/in_snr)+1)
(p(k)*abs(h(k,k))^2)+a-90+(-60/teta(k))<=0;
inv_po (6/(1-teta(k)))-(a-90)<=0
1e-6 <= theta <= 1-1e-6
p >= 1e-6
end
end
cvx_end

`inv_pos` is a CvX function. it is not `inv_po`. And it requires an argument.

help inv_pos

inv_pos Reciprocal of a positive quantity.
inv_pos(X) returns 1./X if X is positive, and +Inf otherwise.
X must be real.

`````` For matrices and N-D arrays, the function is applied to each element.

Disciplined convex programming information:
inv_pos is convex and nonincreasing; therefore, when used in CVX
specifications, its argument must be concave (or affine).
``````

I think you should carefully read the CVX Users’ Guide. http://cvxr.com/cvx/doc/CVX.pdf . You seem to be rather deficient in your understanding of the basics.

ok tnx alot

hello i wrote my code.
clc
clearvars
close all
%% Initial values
t_k = 2; % number of transmitter antenna
r_k = 2; % number of receiver antenna
N = 10^4; % size of data input
N_Realization = 300; % number of channel realization in SISO channel
data_in = randi([0 1], t_k, N); % random data input
SINR_value_db = 6;
Harvestedenergy_value_dbm = -20;
H_MIMO = zeros(t_k,r_k); % defineing channel matrix

%% channel SISO
p_k = rand (1,2); % power of transmitter
p=sqrt (p_k);
k = 0; % SNR loop counter
noise_var=-90
noise_circuit=-60
for SNR_range_variable = SINR_value_db % SNR loop
for w = 1:N_Realization
k = k + 1; % adding in SNR loop counter
% for w = 1:N_Realization % Realization channel loop
H_MIMO = randn (t_k,r_k); % random SISO channel
data_out_ch_SISO =p * H_MIMO * data_in; % pass from SISO channel *
% data_out_ch_AWGN = H_AWGN_KK * data_in; % pass from AWGN channel *
% % reciver
data_out_ch_nois_MIMO(:,:,k) = awgn (data_out_ch_SISO, SNR_range_variable, noise_var); % adding noise MIMO
%data_out_ch_nois_AWGN = awgn (data_out_ch_AWGN, SNR_range_variable, -90); % adding noise AWGN

end
end
%% SINR & EH

for k=1:2;

TETA = randi([0 1], 1 ,2)
mi = randi([0 1], 1 ,2)

norm_h_mimo=norm( [H_MIMO(k,k)],1)
y= p_k * norm([H_MIMO],1)^2 ;

SINR(k) =(TETA(1,k) * p_k(1,k) * norm_h_mimo^2 ) / TETA(1,k) * sum(y,2) + TETA(1,k) * (noise_var ^ 2) + (noise_circuit ^2) ;

POWER_ratio_ID=TETA(1,k)
POWER_ratio_EH=1-TETA(1,k)
EH(k) = mi(1,k) * POWER_ratio_EH * ( sum(y,2) + (noise_var ^ 2));
end
%% optimization

``````in_snr=6;
``````

e=6;
cvx_begin

%%%%for k=1:2;
variable p_k(k)
variable TETA(k)
% dual variable SNR
minimize(sum(p_k))
subject to
SINR >= SINR_value_db
EH >= -20

% minimize teta(k)
%%%% for j=1:k+1;
% k=k+1
%%% h(j,k)=inv_pos (1/sqrt(2))*(randn+i+randn)
% if j==k
% h(j,k)=h(j,k+1);
% else go to 25
% a=
%%%%(j,k)=0
% a = mtimes( j, k, ‘rdivide’ );

%%%%inv_pos -((1/in_snr)+1)* p_k(1,k) * norm_h_mimo^2+ y + noise_var +(-60/TETA(1,k))<=0;
%%%% (6/(1-teta(k)))-(a-90)<=0
%%%%1e-6 <= theta <= 1-1e-6
%%%%p >= 1e-6
%%%%end
%%%%end
% end
cvx_end
i have this result

are they true?
why i have ‘Unbounded’ status or -inf optval?

The solver has determined that your problem is unbounded. Follow the advice in https://yalmip.github.io/debuggingunbounded , which also applies to CVX.