-
Notifications
You must be signed in to change notification settings - Fork 8
/
f_CVX.m
66 lines (46 loc) · 1.13 KB
/
f_CVX.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function [ E,Pb,time,iters ] = f_CVX( coeffs,Pdrv,E0,Pbmin,Pbmax,xmin,xmax,P,C,R,V,misc )
N = length(Pbmin);
rho1 = 2.34E-4;
rho2 = 8.86E-9;
rho1 = 2.34E-4;
rho2 = 1E-8;
normr = [];
normr2 = [];
norms = [];
alpha2 = coeffs(:,1);
alpha1 = coeffs(:,2);
alpha0 = coeffs(:,3);
beta2 = coeffs(:,4);
beta1 = coeffs(:,5);
beta0 = coeffs(:,6);
%% Algorithm
%length of problem
N = length(Pdrv);
%Generate matrices
Phi = ones(N,1);
Psi = tril(ones(N));
%set up while loop
i = 0;
ticmain = tic;
cvx_begin
cvx_precision low
variable Pb(N)
minimize( cost_function(Pb,Pdrv,alpha2,alpha1,alpha0,beta2,beta1,beta0,V,R) )
subject to
Pb <= Pbmax
Pb >= Pbmin
Phi*E0 - Psi*Pb <= Phi*xmax
Phi*E0 - Psi*Pb >= Phi*xmin
%Phi*E0 - cumsum(Pb) <= Phi*xmax
%Phi*E0 - cumsum(Pb) >= Phi*xmin
cvx_end
iters = i;
time = toc(ticmain);
E = E0 - cumsum(Pb);
end
function J = cost_function(Pb,Pdrv,alpha2,alpha1,alpha0,beta2,beta1,beta0,V,R)
ginv = -beta1./2./beta2 + sqrt(-R*Pb.^2./beta2/V^2 + (Pb - beta0)./beta2 + beta1.^2./4./beta2.^2);
Peng = Pdrv - ginv;
Pf = alpha2.*pow_pos(Peng,2) + alpha1.*Peng + alpha0;
J = sum(Pf);
end