pena=1*pena;%可以根据需要修改惩罚系数变量
else
pena=min(1000,c_scale*pena);%%乘法系数最大1000
disp('pena=2*pena');
end
%%?
更新拉格朗日乘子
[h,g]=constrains(x_al);
fori=1:
1
%%等式约束部分
r_al(i)=r_al0(i)+pena*h(i);
end
fori=1:
3
%%不等式约束部分
r_al(i+1)=max(0,(r_al0(i+1)+pena*g(i)));
end
out_itera=out_itera+1;
end
%+++++++++++++++++++++++++++迭代结束+++++++++++++++++++++++++++++++++
disp('theiterationnumber');
k=out_itera;
disp('thevalueofconstrains');
compare(x_al)
disp('theoptpoint');
x=x_al;
fmin=obj(X);
>>clear
>>x_al=[0,0];
>>[x,fmin,k]=almain(x_al)
上机大作业3:
1、
>>clearall
n=3;c=[-3,-1,-3]';A=[2,1,1;1,2,3;2,2,1;-1,0,0;0,-1,0;0,0,-1];b=[2,5,6,0,0,0]';
cvx_begin
variablex(n)
minimize(c'*x)
subjectto
A*x<=b
cvx_end
CallingSDPT34.0:
6variables,3equalityconstraints
------------------------------------------------------------
num.ofconstraints=3
dim.oflinearvar=6
*******************************************************************
SDPT3:
Infeasiblepath-followingalgorithms
*******************************************************************
versionpredcorrgamexponscale_data
NT10.00010
itpstepdsteppinfeasdinfeasgapprim-objdual-objcputime
-------------------------------------------------------------------
0|0.000|0.000|1.1e+01|5.1e+00|6.0e+02|-7.000000e+010.000000e+00|0:
0:
00|chol11
1|0.912|1.000|9.4e-01|4.6e-02|6.5e+01|-5.606627e+00-2.967567e+01|0:
0:
01|chol11
2|1.000|1.000|1.3e-07|4.6e-03|8.5e+00|-2.723981e+00-1.113509e+01|0:
0:
01|chol11
3|1.000|0.961|2.3e-08|6.2e-04|1.8e+00|-4.348354e+00-6.122853e+00|0:
0:
01|chol11
4|0.881|1.000|2.2e-08|4.6e-05|3.7e-01|-5.255152e+00-5.622375e+00|0:
0:
01|chol11
5|0.995|0.962|1.6e-09|6.2e-06|1.5e-02|-5.394782e+00-5.409213e+00|0:
0:
01|chol11
6|0.989|0.989|2.7e-10|5.2e-07|1.7e-04|-5.399940e+00-5.400100e+00|0:
0:
01|chol11
7|0.989|0.989|5.3e-11|5.8e-09|1.8e-06|-5.399999e+00-5.400001e+00|0:
0:
01|chol11
8|1.000|0.994|2.8e-13|4.3e-11|2.7e-08|-5.400000e+00-5.400000e+00|0:
0:
01|
stop:
max(relativegap,infeasibilities)<1.49e-08
-------------------------------------------------------------------
numberofiterations=8
primalobjectivevalue=-5.39999999e+00
dualobjectivevalue=-5.40000002e+00
gap:
=trace(XZ)=2.66e-08
relativegap=2.26e-09
actualrelativegap=2.21e-09
rel.primalinfeas(scaledproblem)=2.77e-13
rel.dual"""=4.31e-11
rel.primalinfeas(unscaledproblem)=0.00e+00
rel.dual"""=0.00e+00
norm(X),norm(y),norm(Z)=4.3e+00,1.3e+00,1.9e+00
norm(A),norm(b),norm(C)=6.7e+00,9.1e+00,5.4e+00
TotalCPUtime(secs)=0.71
CPUtimeperiteration=0.09
terminationcode=0
DIMACS:
3.6e-130.0e+005.8e-110.0e+002.2e-092.3e-09
-------------------------------------------------------------------
------------------------------------------------------------
Status:
Solved
Optimalvalue(cvx_optval):
-5.4
2、
>>clearall
n=2;c=[-2,-4]';G=[0.5,0;0,1];
A=[1,1;-1,0;0,-1];b=[1,0,0]';
cvx_begin
variablex(n)
minimize(x'*G*x+c'*x)
subjectto
A*x<=b
cvx_end
CallingSDPT34.0:
7variables,3equalityconstraints
Forimprovedefficiency,SDPT3issolvingthedualproblem.
------------------------------------------------------------
num.ofconstraints=3
dim.ofsocpvar=4,num.ofsocpblk=1
dim.oflinearvar=3
*******************************************************************
SDPT3:
Infeasiblepath-followingalgorithms
*******************************************************************
versionpredcorrgamexponscale_data
NT10.00010
itpstepdsteppinfeasdinfeasgapprim-objdual-objcputime
-------------------------------------------------------------------
0|0.000|0.000|8.0e-01|6.5e+00|3.1e+02|1.000000e+010.000000e+00|0:
0:
00|chol11
1|1.000|0.987|4.3e-07|1.5e-01|1.6e+01|9.043148e+00-2.714056e-01|0:
0:
00|chol11
2|1.000|1.000|2.6e-07|7.6e-03|1.4e+00|1.234938e+00-5.011630e-02|0:
0:
00|chol11
3|1.000|1.000|2.4e-07|7.6e-04|3.0e-01|4.166959e-011.181563e-01|0:
0:
00|chol11
4|0.892|0.877|6.4e-08|1.6e-04|5.2e-02|2.773022e-012.265122e-01|0:
0:
00|chol11
5|1.000|1.000|1.0e-08|7.6e-06|1.5e-02|2.579468e-012.427203e-01|0:
0:
00|chol11
6|0.905|0.904|3.1e-09|1.4e-06|2.3e-03|2.511936e-012.488619e-01|0:
0:
00|chol11
7|1.000|1.000|6.1e-09|7.7e-08|6.6e-04|2.503336e-012.496718e-01|0:
0:
00|chol11
8|0.903|0.903|1.8e-09|1.5e-08|1.0e-04|2.500507e-012.499497e-01|0:
0:
00|chol11
9|1.000|1.000|4.9e-10|3.5e-10|2.9e-05|2.500143e-012.499857e-01|0:
0:
00|chol11
10|0.904|0.904|4.7e-11|1.3e-10|4.4e-06|2.500022e-012.499978e-01|0:
0:
00|chol22
11|1.000|1.000|2.3e-12|9.4e-12|1.2e-06|2.500006e-012.499994e-01|0:
0:
00|chol22
12|1.000|1.000|4.7e-13|1.0e-12|1.8e-07|2.500001e-012.499999e-01|0:
0:
00|chol22
13|1.000|1.000|2.0e-12|1.0e-12|4.2e-08|2.500000e-012.500000e-01|0:
0:
00|chol22
14|1.000|1.000|2.6e-12|1.0e-12|7.3e-09|2.500000e-012.500000e-01|0:
0:
00|
stop:
max(relativegap,infeasibilities)<1.49e-08
----------------------------