Why such high precision

Hello! I have been having this problem that the solution obtained by cvx is so small, sometimes even to 10^(-20) or 10^(-30), it is approximately 0. Why doesn’t cvx just give me a 0 and I do not need this high precision. This high precision has made the problem NAN.

And, why do I get NAN as the optimization result while all the variables are solved. And when I type the objective function into the command, I can get an exact result. I am so confused QAQ

If you show us your complete reproducible problem, with all input data, and show us all CVX and solver output, perhaps more specific guidance cam be provided.

NEVER use cvx_precision high in CVX. Don’t use the cvx_precision statement at all The CVX developer included it with the best of intentions, but the collective expertise and experience on this forum is that it is sometimes a bad thing to do, and almost never a good thing to do.

It might also be the case the your problem is badly scaled numerically. Change units of variables so that all non-zero input numbers are within a small number of orders of magnitude of 1.

These are just guesses, because you haven’t provided adequate information.

if CVX reports Failed, all CVX variable values are meaningless, and if not already NaN, should be considered to be.

My optimization problem is just one linear programming problem, with A1-A9 being matrix, w and f being variables. I have presented in the picture the solution of f in one time, you can see that it is in the order of 10^(-12), and I only need it to be 0 if it is so small. In fact, the value of it being so small instead of 0 makes some of the constraints invalid, for example, for the constraint A8*f==0, since some of the variables are 10^(-12), so A8*f is in the order of 10^(-12) instead of 0, so the problem is NAN. I this this is the reason that makes the problem unsolvable.

Is there any way to round the variables to 0 directly?

You have to do the rounding yourself after you get the results. This is floating point-arithmetic, you only ever get the results up to certain precision. Except for some trivial problems the solution never satisfies all constraints exactly. See for example https://docs.mosek.com/modeling-cookbook/practical.html#the-quality-of-a-solution

To say anything about why CVX reported Failed please post the full log output or reproducible code. The last bit of the log from your first post contains some humongous statistics in the norm section, so probably your problem is badly scaled and therefore does not solve.

Here is the full log output, it is indeed very long, does it mean that it is badly scaled?

Calling SDPT3 4.0: 2304 variables, 451 equality constraints

num. of constraints = 451
dim. of linear var = 2304
number of nearly dependent constraints = 441
To remove these constraints, re-run sqlp.m with OPTIONS.rmdepconstr = 1.


SDPT3: Infeasible path-following algorithms


version predcorr gam expon scale_data
NT 1 0.000 1 0
it pstep dstep pinfeas dinfeas gap prim-obj dual-obj cputime

0|0.000|0.000|2.2e+13|7.6e+13|9.6e+17|-9.600000e+02 0.000000e+00| 0:0:00| chol * 3 * 3
1|0.350|0.078|1.4e+13|7.0e+13|7.6e+17|-2.133350e+03 -2.897042e+12| 0:0:00| chol * 3 * 3
2|0.289|0.346|1.0e+13|4.6e+13|6.4e+17|-2.406912e+03 -2.029151e+13| 0:0:00| chol * 3 * 3
3|0.284|0.362|7.2e+12|2.9e+13|5.4e+17|-2.714971e+03 -3.873101e+13| 0:0:00| chol * 3 * 3
4|0.458|0.584|3.9e+12|1.2e+13|3.7e+17|-2.717186e+03 -7.862434e+13| 0:0:00| chol * 3 * 3
5|0.569|0.934|1.7e+12|8.0e+11|2.5e+17|-1.383553e+03 -1.874370e+14| 0:0:00| chol 2 2
6|0.982|0.982|3.1e+10|1.4e+10|4.7e+15|-2.776148e+01 -1.909330e+14| 0:0:00| chol 2 2
7|0.948|0.986|1.6e+09|2.1e+08|3.8e+14|-3.622912e+00 -1.657930e+14| 0:0:00| chol 2 2
8|0.272|0.685|1.2e+09|6.5e+07|2.9e+14|-3.218338e+00 -1.244843e+14| 0:0:00| chol 2 2
9|0.036|0.096|1.1e+09|5.9e+07|2.9e+14|-3.115610e+00 -1.126872e+14| 0:0:00| chol 2 2
10|0.242|0.336|8.5e+08|3.9e+07|2.7e+14|-2.517026e+00 -1.017758e+14| 0:0:00| chol 2 2
11|0.332|0.324|5.7e+08|2.6e+07|2.3e+14|-1.907562e+00 -9.463465e+13| 0:0:00| chol 2 2
12|0.464|0.557|3.1e+08|1.2e+07|1.7e+14|-1.376551e+00 -8.094792e+13| 0:0:00| chol 2 2
13|0.565|0.745|1.3e+08|3.0e+06|1.1e+14|-1.048548e+00 -5.548914e+13| 0:0:00| chol 2 2
14|0.709|0.781|3.9e+07|6.5e+05|6.6e+13|-7.203732e-01 -4.649647e+13| 0:0:00| chol 2 2
15|0.600|0.745|1.5e+07|1.7e+05|4.2e+13|-6.064860e-01 -3.282392e+13| 0:0:00| chol 1 2
16|0.529|0.346|7.3e+06|1.1e+05|3.4e+13|-5.641109e-01 -2.911126e+13| 0:0:00| chol 1 2
17|0.542|0.057|3.3e+06|1.0e+05|3.2e+13|-5.570183e-01 -2.851851e+13| 0:0:00| chol 1 2
18|0.408|0.163|2.0e+06|8.5e+04|3.0e+13|-6.092478e-01 -2.548566e+13| 0:0:00| chol 1 * 3
19|0.613|0.418|7.6e+05|5.0e+04|2.0e+13|-6.488204e-01 -1.691120e+13| 0:0:00| chol 2 2
20|0.775|0.325|1.7e+05|3.4e+04|1.5e+13|-7.318135e-01 -1.211289e+13| 0:0:00| chol * 3 2
21|0.960|0.698|6.8e+03|1.0e+04|5.2e+12|-7.804900e-01 -4.020937e+12| 0:0:00| chol 2 2
22|0.980|0.984|1.4e+02|1.6e+02|8.3e+10|-7.807060e-01 -6.426054e+10| 0:0:00| chol
linsysolve: Schur complement matrix not positive definite
switch to LU factor. lu 27 1
23|0.988|0.989|1.6e+00|2.6e+00|9.3e+08|-7.807079e-01 -7.227201e+08| 0:0:00| lu 28 1
24|0.171|0.210|1.3e+00|9.4e+00|8.8e+08|-8.966749e-01 -6.045427e+08| 0:0:00| lu 11 1
25|0.034|0.032|1.3e+00|1.1e+01|9.2e+08|-1.006235e+00 -5.568238e+08| 0:0:00| lu 15 1
26|0.216|0.227|1.0e+00|1.3e+01|8.4e+08|-1.111526e+00 -4.459430e+08| 0:0:00| lu 12 1
27|0.690|0.679|3.1e-01|1.7e+01|2.9e+08|-1.176938e+00 -1.335255e+08| 0:0:00| lu 13 1
28|0.986|0.986|4.2e-03|1.5e+01|3.9e+06|-1.176963e+00 -1.829274e+06| 0:0:00| lu 11 1
29|1.000|0.707|9.2e-06|1.6e+01|1.3e+06|-1.216792e+00 -6.204800e+05| 0:0:00| lu 11 1
30|0.997|0.729|1.6e-05|1.6e+01|3.7e+05|-1.253502e+00 -1.773124e+05| 0:0:00| lu 13 1
31|1.000|0.804|2.1e-05|1.5e+01|4.8e+04|-1.262102e+00 -1.001259e+04| 0:0:00| lu 21 1
32|0.992|0.961|5.4e-06|1.7e+01|1.9e+03|-1.279580e+00 -3.969043e+02| 0:0:00| lu 11 1
33|1.000|0.847|2.5e-05|1.6e+01|3.4e+02|-1.502286e+00 -1.021915e+02| 0:0:00| lu 11 1
34|1.000|0.770|1.3e-05|1.6e+01|1.7e+02|-1.796964e+00 -8.463611e+01| 0:0:00| lu 21 1
35|1.000|0.811|1.2e-05|1.5e+01|5.6e+01|-2.016785e+00 -3.828756e+01| 0:0:00| lu 11 1
36|0.080|0.107|1.1e-05|1.8e+01|5.7e+01|-2.143549e+00 -3.980277e+01| 0:0:00| lu 11 1
37|0.317|0.182|9.4e-06|1.9e+01|5.7e+01|-2.423573e+00 -4.017767e+01| 0:0:00| lu 23 1
38|0.808|0.731|1.0e-05|1.6e+01|3.3e+01|-2.774517e+00 -2.763625e+01| 0:0:00| lu 27 1
39|0.804|0.769|2.2e-07|1.5e+01|1.8e+01|-2.953840e+00 -1.754661e+01| 0:0:00| lu 11 30
40|0.035|0.132|7.0e-07|1.7e+01|2.0e+01|-3.006735e+00 -1.988905e+01| 0:0:00| lu 11 1
41|0.014|0.021|6.1e-07|1.8e+01|2.1e+01|-3.011925e+00 -2.023381e+01| 0:0:00| lu 11 1
42|0.048|0.088|2.3e-07|2.1e+01|2.2e+01|-3.061072e+00 -2.160932e+01| 0:0:00| lu 11 1
43|0.226|0.376|1.3e-05|1.7e+01|2.6e+01|-3.243219e+00 -2.600848e+01| 0:0:00| lu 20 ^15
44|0.556|0.575|1.1e-05|1.8e+01|2.0e+01|-3.285280e+00 -2.022063e+01| 0:0:00| lu 30 1
45|0.562|0.497|2.0e-05|1.2e+01|1.5e+01|-3.365448e+00 -1.595765e+01| 0:0:00| lu 12 1
46|0.041|0.050|2.0e-05|1.1e+01|1.5e+01|-3.403722e+00 -1.644248e+01| 0:0:00| lu 13 1
47|0.186|0.345|1.7e-05|1.1e+01|1.5e+01|-3.430394e+00 -1.581001e+01| 0:0:00| lu 14 1
48|0.199|0.402|8.6e-06|9.4e+00|1.3e+01|-3.470770e+00 -1.418508e+01| 0:0:00| lu 30 1
49|0.398|0.482|1.2e-05|1.3e+01|1.0e+01|-3.609457e+00 -1.261247e+01| 0:0:00| lu 26 1
50|0.562|0.667|4.5e-06|8.0e+00|7.7e+00|-3.823145e+00 -1.110685e+01| 0:0:00| lu 30 1
51|0.659|0.508|4.4e-06|1.7e+01|6.0e+00|-4.076885e+00 -9.592546e+00| 0:0:00| lu 13 1
52|0.598|0.413|3.8e-06|1.8e+01|5.1e+00|-4.344054e+00 -9.427937e+00| 0:0:00| lu 11 ^26
53|0.001|0.018|3.1e-06|2.0e+01|7.2e+00|-4.352757e+00 -1.147430e+01| 0:0:00| lu 21 1
54|0.571|0.170|3.0e-05|2.2e+01|7.3e+00|-4.134903e+00 -1.098338e+01| 0:0:00| lu 30 ^28
55|0.846|1.000|2.2e-05|1.7e+01|4.1e+00|-4.402202e+00 -8.850590e+00| 0:0:01| lu 11 ^20
56|0.005|0.010|3.5e-05|1.8e+01|4.5e+00|-4.399828e+00 -9.256672e+00| 0:0:01| lu 30 1
57|1.000|0.236|3.7e-05|1.7e+01|4.2e+00|-4.404412e+00 -8.833937e+00| 0:0:01| lu 11 1
58|0.005|0.004|5.8e-05|1.8e+01|4.2e+00|-4.411113e+00 -8.876875e+00| 0:0:01| lu 11 ^ 7
59|0.003|0.006|7.4e-05|1.8e+01|4.6e+00|-4.439025e+00 -9.339369e+00| 0:0:01| lu 11 7
60|0.035|0.015|6.1e-05|1.8e+01|4.8e+00|-4.459122e+00 -9.516925e+00| 0:0:01| lu 11 1
61|0.016|0.054|4.4e-05|1.9e+01|5.7e+00|-4.469397e+00 -1.038938e+01| 0:0:01| lu 30 1
62|0.231|0.191|3.8e-05|1.9e+01|5.5e+00|-4.436309e+00 -1.007267e+01| 0:0:01| lu 11 ^ 5
63|0.026|0.039|6.1e-05|2.2e+01|6.6e+00|-4.485497e+00 -1.121124e+01| 0:0:01| lu 11 ^10
64|0.063|0.067|6.5e-05|2.2e+01|7.8e+00|-4.498282e+00 -1.229677e+01| 0:0:01| lu 15 1
65|0.091|0.295|7.3e-05|2.0e+01|7.2e+00|-4.472602e+00 -1.166038e+01| 0:0:01| lu 11 ^ 5
66|0.046|0.035|6.5e-05|2.0e+01|7.8e+00|-4.469411e+00 -1.220599e+01| 0:0:01| lu 11 1
67|0.114|0.097|1.4e-04|2.0e+01|9.6e+00|-4.550455e+00 -1.409916e+01| 0:0:01| lu 11 ^ 6
68|0.175|0.088|5.2e-05|1.9e+01|1.1e+01|-4.536359e+00 -1.504404e+01| 0:0:01| lu 11 1
69|0.186|1.000|7.2e-05|1.5e+01|2.2e+01|-4.569107e+00 -2.740208e+01| 0:0:01| lu 30 1
70|0.294|0.314|3.0e-04|1.7e+01|2.0e+01|-4.313205e+00 -2.366584e+01| 0:0:01| lu 11 1
71|0.238|0.263|2.9e-04|1.5e+01|2.0e+01|-4.116976e+00 -2.334744e+01| 0:0:01| lu 11 1
72|0.013|0.019|2.8e-04|1.6e+01|2.0e+01|-4.109578e+00 -2.343679e+01| 0:0:01| lu 11 1
73|0.214|0.124|2.3e-04|1.6e+01|2.1e+01|-3.983264e+00 -2.361893e+01| 0:0:01| lu 11 ^15
74|0.009|0.078|2.3e-04|1.8e+01|2.2e+01|-3.985117e+00 -2.457086e+01| 0:0:01| lu 13 1
75|0.950|0.307|4.0e-05|1.6e+01|2.0e+01|-3.624272e+00 -2.198023e+01| 0:0:01| lu 14 1
76|0.927|0.359|7.5e-05|1.4e+01|1.8e+01|-3.457201e+00 -1.923011e+01| 0:0:01| lu 11 1
77|0.013|0.025|7.4e-05|1.5e+01|1.8e+01|-3.468344e+00 -1.971902e+01| 0:0:01| lu 14 1
78|0.411|0.824|1.1e-05|1.1e+01|1.3e+01|-3.563834e+00 -1.500243e+01| 0:0:01| lu 30 1
79|0.473|0.522|1.2e-05|9.9e+00|1.0e+01|-3.628029e+00 -1.263056e+01| 0:0:01| lu 30 1
80|0.459|0.346|7.9e-06|8.4e+00|9.2e+00|-3.758734e+00 -1.208996e+01| 0:0:01| lu 11 1
81|0.015|0.041|1.9e-05|9.1e+00|1.0e+01|-3.793823e+00 -1.322930e+01| 0:0:01| lu 30 1
82|0.677|0.452|9.5e-05|1.1e+01|8.0e+00|-3.832845e+00 -1.096560e+01| 0:0:01| lu 11 ^24
83|0.005|0.009|1.0e-04|1.3e+01|8.1e+00|-3.838541e+00 -1.107158e+01| 0:0:01| lu 11 5
84|0.120|0.039|9.7e-05|1.4e+01|8.3e+00|-3.940205e+00 -1.141262e+01| 0:0:01| lu 11 1
85|0.065|0.048|1.0e-04|1.5e+01|8.7e+00|-3.989145e+00 -1.190559e+01| 0:0:01| lu 30 1
86|0.255|0.279|7.9e-05|1.3e+01|8.2e+00|-3.989277e+00 -1.164076e+01| 0:0:01| lu 11 2
87|0.058|0.080|7.5e-05|1.3e+01|9.0e+00|-4.032252e+00 -1.248223e+01| 0:0:01| lu 11 ^10
88|0.108|0.224|7.7e-05|2.1e+01|1.0e+01|-4.057420e+00 -1.380344e+01| 0:0:01| lu 26 1
89|0.184|0.777|6.7e-05|1.1e+01|8.5e+00|-4.057604e+00 -1.259750e+01| 0:0:01| lu 11 ^16
90|0.028|0.053|6.0e-05|1.6e+01|9.1e+00|-4.076334e+00 -1.321453e+01| 0:0:01| lu 11 1
91|0.225|0.221|4.6e-05|1.5e+01|1.0e+01|-4.064618e+00 -1.435039e+01| 0:0:01| lu 12 1
92|0.045|0.194|5.3e-05|1.7e+01|1.3e+01|-4.091679e+00 -1.683258e+01| 0:0:01| lu 11 ^25
93|0.010|0.025|5.4e-05|1.9e+01|1.4e+01|-4.086975e+00 -1.733897e+01| 0:0:01| lu 11 1
94|0.014|0.031|5.1e-05|2.0e+01|1.4e+01|-4.081330e+00 -1.777175e+01| 0:0:01| lu 11 1
95|0.019|0.028|5.1e-05|2.1e+01|1.4e+01|-4.076245e+00 -1.783051e+01| 0:0:01| lu 11 1
96|0.266|0.198|3.0e-05|1.9e+01|1.5e+01|-3.932588e+00 -1.853358e+01| 0:0:01| lu 11 1
97|0.290|0.442|2.1e-05|1.7e+01|1.7e+01|-3.911953e+00 -1.970615e+01| 0:0:01| lu 16 ^10
98|0.290|0.840|1.1e-05|1.7e+01|1.0e+01|-3.859145e+00 -1.314664e+01| 0:0:01| lu 11 1
99|0.018|0.025|1.1e-05|1.7e+01|1.1e+01|-3.881246e+00 -1.352217e+01| 0:0:01| lu 30 1
100|0.443|0.580|1.4e-05|1.5e+01|8.2e+00|-3.918502e+00 -1.131531e+01| 0:0:01|
sqlp stop: maximum number of iterations reached

number of iterations = 100
primal objective value = -7.80707903e-01
dual objective value = -7.22720073e+08
gap := trace(XZ) = 9.31e+08
relative gap = 1.29e+00
actual relative gap = 1.00e+00
rel. primal infeas (scaled problem) = 1.59e+00
rel. dual " " " = 2.57e+00
rel. primal infeas (unscaled problem) = 0.00e+00
rel. dual " " " = 0.00e+00
norm(X), norm(y), norm(Z) = 9.1e+08, 5.7e+16, 5.7e+16
norm(A), norm(b), norm© = 1.3e+13, 3.3e+01, 5.5e+00
Total CPU time (secs) = 0.91
CPU time per iteration = 0.01
termination code = -6
DIMACS: 4.7e+00 0.0e+00 7.0e+00 0.0e+00 1.0e+00 1.3e+00


Status: Failed
Optimal value (cvx_optval): NaN

It reaches maximal number of iterations and at that point the solution has huge norms and gap, so yes, your problem is extremely bad numerically and/or ill-posed in some way. Maybe a reading of https://docs.mosek.com/modeling-cookbook/practical.html#practical-optimization can give you some hints about how to rescale/improve it. I would start by checking that the magnitude of the data you feed, and the magnitude of the expected solution in is in reasonable range and then maybe also if the problem is not borderline infeasible. Good luck.