0% found this document useful (0 votes)
80 views10 pages

DET hw3

The document contains the code for solving four convex optimization problems using CVX. The first problem involves maximizing a weighted sum subject to constraints on four vectors. The second problem involves fitting a polynomial to data by minimizing the residuals subject to bounds. The third problem is the same as the second but with fewer constraints. The fourth problem involves minimizing a weighted objective subject to inequality constraints on three vectors.

Uploaded by

Anna Simmons
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views10 pages

DET hw3

The document contains the code for solving four convex optimization problems using CVX. The first problem involves maximizing a weighted sum subject to constraints on four vectors. The second problem involves fitting a polynomial to data by minimizing the residuals subject to bounds. The third problem is the same as the second but with fewer constraints. The fourth problem involves minimizing a weighted objective subject to inequality constraints on three vectors.

Uploaded by

Anna Simmons
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Scanned by CamScanner

Scanned by CamScanner

))1
>> cvx_begin
variables x1(6) x2(6) x3(6) x4(6)
>> A=[3,12,5,8,3,10;4,10,11,12,7,2;4,14,3,31,9,15;2,7,1,1,3,10]
A=
3 12

3 10

4 10 11 12

4 14

3 31

9 15

3 10

>> maximize (sum(x1'.*A(1,:))+sum(x2'.*A(2,:))+sum(x3'.*A(3,:))+sum(x4'.*A(4,:)))


>> subject to
>> sum(x1)==1
>> sum(x2)==1
>> sum(x3)==1
>> sum(x4)==1
>> x1(1)+x2(1)+x3(1)+x4(1)<=1
>> x1(2)+x2(2)+x3(2)+x4(2)<=1
>> x1(3)+x2(3)+x3(3)+x4(3)<=1
>> x1(4)+x2(4)+x3(4)+x4(4)<=1
>> x1(5)+x2(5)+x3(5)+x4(5)<=1
>> x1(6)+x2(6)+x3(6)+x4(6)<=1

>> x1>=0
>> x2>=0
>> x3>=0
>> x4>=0
>> cvx_end

Calling sedumi: 42 variables, 22 equality constraints


-----------------------------------------------------------SeDuMi 1.21 by AdvOL, 2005-2008 and Jos F. Sturm, 1998-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
eqs m = 22, order n = 43, dim = 43, blocks = 1
nnz(A) = 78 + 0, nnz(ADA) = 118, nnz(L) = 76
it :
0:

b*y

gap delta rate t/tP* t/tD* feas cg cg prec


8.11E-02 0.000

1 : -4.08E+01 4.55E-02 0.000 0.5608 0.9000 0.9000 4.38 1 1 3.1E+00


2 : -5.43E+01 1.41E-02 0.000 0.3106 0.9000 0.9000 1.90 1 1 6.6E-01
3 : -6.19E+01 3.15E-03 0.000 0.2232 0.9000 0.9000 1.14 1 1 1.4E-01
4 : -6.40E+01 1.85E-05 0.000 0.0059 0.9990 0.9990 1.02 1 1
iter seconds digits
4

c*x

b*y

0.1 15.7 -6.4000000000e+01 -6.4000000000e+01

|Ax-b| = 4.9e-16, [Ay-c]_+ = 2.1E-19, |x|= 2.8e+00, |y|= 3.1e+01

Detailed timing (sec)


Pre

IPM

Post

1.560E-02 6.240E-02 3.120E-02


Max-norms: ||b||=1, ||c|| = 31,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 1.
-----------------------------------------------------------Status: Solved
Optimal value (cvx_optval): +64
:
2 1
3 -2
4 3
6 -4

))3
>> cvx_begin
>> variables a b c d z(61)
>> minimize sum(z)
>> subject to
>> z>=((a*(x.^3)+b*(x.^2)+c*x+d)-y)
>> z>=-((a*(x.^3)+b*(x.^2)+c*x+d)-y)
>> cvx_end

Calling sedumi: 122 variables, 65 equality constraints


For improved efficiency, sedumi is solving the dual problem.
-----------------------------------------------------------SeDuMi 1.21 by AdvOL, 2005-2008 and Jos F. Sturm, 1998-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
eqs m = 65, order n = 123, dim = 123, blocks = 1
nnz(A) = 363 + 0, nnz(ADA) = 559, nnz(L) = 312
it :
0:

b*y

gap delta rate t/tP* t/tD* feas cg cg prec


7.45E-02 0.000

1 : -1.33E+04 1.99E-02 0.000 0.2670 0.9000 0.9000 0.90 1 1 1.8E+02


2 : -5.35E+03 1.14E-02 0.000 0.5750 0.9000 0.9000 3.96 1 1 3.6E+01
3 : -1.01E+03 6.17E-03 0.000 0.5396 0.9000 0.9000 8.86 1 1 3.1E+00
4 : -7.16E+02 1.60E-03 0.000 0.2585 0.9000 0.9000 2.14 1 1 5.0E-01
5 : -6.86E+02 3.67E-04 0.000 0.2300 0.9000 0.9000 1.18 1 1 1.1E-01
6 : -6.81E+02 1.06E-04 0.000 0.2901 0.9000 0.9000 1.03 1 1 3.1E-02
7 : -6.80E+02 1.63E-05 0.000 0.1534 0.8863 0.9000 1.01 1 1 6.3E-03
8 : -6.79E+02 3.64E-06 0.000 0.2226 0.9000 0.9000 1.00 1 1 1.4E-03
9 : -6.79E+02 7.45E-08 0.000 0.0205 0.9900 0.9900 1.00 1 1
iter seconds digits
9

c*x

b*y

0.1 15.2 -6.7892920077e+02 -6.7892920077e+02

|Ax-b| = 5.8e-14, [Ay-c]_+ = 1.3E-14, |x|= 7.7e+00, |y|= 5.2e+01

Detailed timing (sec)


Pre

IPM

Post

3.120E-02 7.800E-02 0.000E+00


Max-norms: ||b||=1.891000e+02, ||c|| = 3.290302e+02,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 48.778.
-----------------------------------------------------------Status: Solved
Optimal value (cvx_optval): +360.548

)
>> cvx_begin
>> variables a b c d z
>> minimize z
>> z>=((a*(x.^3)+b*(x.^2)+c*x+d)-y)
>> z>=-((a*(x.^3)+b*(x.^2)+c*x+d)-y)
>> cvx_end

Calling sedumi: 122 variables, 5 equality constraints


For improved efficiency, sedumi is solving the dual problem.
-----------------------------------------------------------SeDuMi 1.21 by AdvOL, 2005-2008 and Jos F. Sturm, 1998-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
eqs m = 5, order n = 123, dim = 123, blocks = 1
nnz(A) = 604 + 0, nnz(ADA) = 25, nnz(L) = 15
it :
0:

b*y

gap delta rate t/tP* t/tD* feas cg cg prec


8.21E+00 0.000

1 : -1.75E+02 7.45E-01 0.000 0.0908 0.9900 0.9900 0.17 1 1 2.6E+01


2 : -1.12E+02 1.53E-01 0.000 0.2057 0.9000 0.9000 2.19 1 1 3.2E+00
3 : -7.72E+01 4.59E-02 0.000 0.2995 0.9000 0.9000 1.90 1 1 6.6E-01
4 : -7.48E+01 1.48E-02 0.000 0.3228 0.9000 0.9000 1.16 1 1 2.1E-01
5 : -7.47E+01 3.75E-03 0.000 0.2533 0.9000 0.9000 1.02 1 1 5.2E-02
6 : -7.45E+01 3.15E-05 0.000 0.0084 0.9900 0.9697 1.01 1 1 2.3E-03
7 : -7.45E+01 1.05E-05 0.000 0.3347 0.7195 0.9000 1.00 1 1 7.8E-04
8 : -7.45E+01 4.71E-06 0.000 0.4476 0.5859 0.9000 1.00 1 1 3.5E-04
9 : -7.45E+01 1.65E-06 0.000 0.3502 0.9000 0.9000 1.00 1 1 1.2E-04
10 : -7.45E+01 3.28E-08 0.000 0.0199 0.9900 0.9900 1.00 1 1
iter seconds digits
10

c*x

b*y

0.1 15.4 -7.4482195701e+01 -7.4482195701e+01

|Ax-b| = 4.7e-16, [Ay-c]_+ = 9.0E-15, |x|= 6.4e-01, |y|= 1.0e+02

Detailed timing (sec)


Pre

IPM

Post

0.000E+00 6.240E-02 0.000E+00


Max-norms: ||b||=1, ||c|| = 1.645151e+02,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 63.6379.
-----------------------------------------------------------Status: Solved
Optimal value (cvx_optval): +74.4822

:cvx ) 4
>> cvx_begin
>> variables x1(4) x2(4) x3(4)
>> minimize 42*(x1(1))+50*(x1(2))+2*(x1(1)-x1(3))+30*(x2(1))+45*(x2(2))+2*(x2(1)-x2(3))+36*(x3(1))+32*(x3(2))+2*(x3(1)-x3(3))
>> subject to
>> 90*(x1(3))+40*(x2(3))+20*(x3(3))>=1400
30*(x1(3))+60*(x2(3))+80*(x3(3))>=1260
10*(x1(3))+50*(x2(3))+20*(x3(3))>=1050
>> 90*x1(4)+40*x2(4)+20*x3(4)>=1400
30*(x1(4))+60*(x2(4))+80*(x3(4))>=1260
10*(x1(4))+50*(x2(4))+20*(x3(4))>=1050
x1(1)>=x1(3)
x2(1)>=x2(3)
x3(1)>=x3(3)
x1(2)+(x1(1)-x1(3))>=x1(4)
x2(2)+(x2(1)-x2(3))>=x2(4)

x3(2)+(x3(1)-x3(3))>=x3(4)
x1>=0
x2>=0
x3>=0
>> cvx_end

Calling sedumi: 24 variables, 12 equality constraints


For improved efficiency, sedumi is solving the dual problem.
-----------------------------------------------------------SeDuMi 1.21 by AdvOL, 2005-2008 and Jos F. Sturm, 1998-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
eqs m = 12, order n = 25, dim = 25, blocks = 1
nnz(A) = 48 + 0, nnz(ADA) = 60, nnz(L) = 39
it :
0:

b*y

gap delta rate t/tP* t/tD* feas cg cg prec


5.17E-02 0.000

1 : 4.89E+03 1.68E-02 0.000 0.3238 0.9000 0.9000 2.93 1 1 4.7E+01


2 : 1.89E+02 3.68E-03 0.000 0.2199 0.9000 0.9000 1.56 1 1 7.9E+00
3 : -1.35E+03 1.14E-03 0.000 0.3084 0.9000 0.9000 1.49 1 1 1.8E+00
4 : -1.73E+03 3.57E-04 0.000 0.3144 0.9000 0.9000 1.77 1 1 4.2E-01
5 : -1.80E+03 2.89E-05 0.000 0.0808 0.9900 0.9900 1.20 1 1 3.1E-02
6 : -1.80E+03 8.77E-08 0.000 0.0030 0.9990 0.9990 1.00 1 1
iter seconds digits
6

c*x

b*y

0.0 Inf -1.8046341463e+03 -1.8046341463e+03

|Ax-b| = 1.7e-14, [Ay-c]_+ = 2.0E-18, |x|= 6.4e+01, |y|= 5.1e+01

Detailed timing (sec)


Pre

IPM

Post

0.000E+00 1.560E-02 0.000E+00


Max-norms: ||b||=50, ||c|| = 1400,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 1.96342.
------------------------------------------------------------

Status: Solved
Optimal value (cvx_optval): +1804.63

You might also like