# Minimize : Too many output arguments

I want to calculate the minimum value.
And Already the function I made is proved as a convex function.

Actually, I am looking for a function such as “fminsearch”.
So I choose the “minimize” function in cvx, but the error comes up.

``````previous by using fminsearch:
len1 = @(x) ~~~~;
...
len16 = @(x) ~~~~;
myfun = @(x) len1(x)+len2(x)+len3(x)+....+len16(x);
[x,fval] = fminsearch(myfun, [0,0,0,0,0,0,0,0,0,0,0,0]);
``````

``````now by using cvx:

variables x1 x2 ..... x12
len1 = norm( using x1~x12);
...
len16 = norm( using x1~x12);

myfun = minimize(len1+len2+....+len16);
``````

-> Error using minimize
Too many output arguments.

Should I make the function as an input for minimize
such as A*x - b ??

Help me…!

Please show exact and complete code of what you tried and the output which was produced, or at least a minimal reproducible example which is complete and illustrates your problem.

1 Like

why are you trying to assign the output of `minimize` to a variable? Just do

1 Like

As mcg wrote, don’t use
`tolen(n) = minimize(...);`
Get rid of
`tolen(n) =`

Are you trying to save the optimal objective value each time minimize is called? if so, insert the line
`tolen(n) = cvx_optval;`
after the minimize statement.

1 Like

Oh, I tried but error occurs:

```Undefined function or variable 'cvx_optval'.``

Sorry. cvx_optval needs to come after cvx_end

If you want to call minimize each time through the nested loops, you need to put cvx_begin, CVX variable declarations, and all expressions (and constraints if you had any) between the cvx_begin and cvx_end, which should all be inside the innermost loop.

1 Like

Thank you very much.
Now it works and the results seem satisfying.

One more question here:

The cvx output(like the below) is very long and much.(Since there’re more than 1000 iterations…)
I want to save(hide) the outputs in a file in order not to show on the command window.

``````Calling SDPT3 4.0: 12 variables, 2 equality constraints
------------------------------------------------------------

num. of constraints =  2
dim. of socp   var  = 12,   num. of socp blk  =  4
*******************************************************************
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|3.8e-01|6.0e+00|2.1e+01| 0.000000e+00  0.000000e+00| 0:0:00| chol  1  1
1|1.000|0.997|4.6e-09|1.2e-01|3.9e-01| 0.000000e+00  5.244599e-03| 0:0:00| chol  1  1
2|1.000|1.000|6.8e-08|1.0e-02|2.8e-02| 0.000000e+00  7.256085e-04| 0:0:00| chol  1  1
3|1.000|1.000|3.2e-08|1.0e-03|2.2e-03| 0.000000e+00  1.046287e-04| 0:0:00| chol  1  1
4|1.000|1.000|1.1e-08|1.0e-04|1.8e-04| 0.000000e+00  1.404183e-05| 0:0:00| chol  1  1
5|1.000|1.000|1.6e-10|1.0e-05|1.4e-05| 0.000000e+00  1.779475e-06| 0:0:00| chol  1  1
6|1.000|0.989|1.1e-11|1.1e-07|1.5e-07| 0.000000e+00  1.939589e-08| 0:0:00| chol  1  1
7|1.000|0.988|6.3e-14|1.3e-09|1.9e-09| 0.000000e+00  1.779273e-10| 0:0:00|
stop: max(relative gap, infeasibilities) < 1.49e-08
-------------------------------------------------------------------
number of iterations   =  7
primal objective value =  0.00000000e+00
dual   objective value =  1.77927349e-10
gap := trace(XZ)       = 1.91e-09
relative gap           = 1.91e-09
actual relative gap    = -1.78e-10
rel. primal infeas (scaled problem)   = 6.33e-14
rel. dual     "        "       "      = 1.32e-09
rel. primal infeas (unscaled problem) = 0.00e+00
rel. dual     "        "       "      = 0.00e+00
norm(X), norm(y), norm(Z) = 1.6e+00, 2.9e-10, 1.4e-09
norm(A), norm(b), norm(C) = 3.8e+00, 1.6e+00, 1.0e+00
Total CPU time (secs)  = 0.06
CPU time per iteration = 0.01
termination code       =  0
DIMACS: 6.3e-14  0.0e+00  1.3e-09  0.0e+00  -1.8e-10  1.9e-09
-------------------------------------------------------------------

------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0``````

You can use
`cvx_begin quiet`
in order to suppress all the CVX output. You can rely on MATLAB inspection in your code and/or saving the values of the CVX variable output values, cvx_optval, and cvx_status to assess the results of each CVX invocation. You can use the MATLAB diary command if you want to save a copy of all the CVX output (without using quiet option).

1 Like

If you have 1296 optimization problems to solve, then you need to have 1296 occurrences of cvx_begin … cvx_end.

Are you getting the correct answer as far as you know? if so, it is a question of run time. You can try moving everything possible out of the for loops, but perhaps yuu have already done that. If so, if you want to speed things up, you may have to use a different tool which doesn’t incur CVX’s overhead

1 Like

Fortunately, I am getting the correct answer as far as I know.
And it takes less than 10 minutes for 1296 iteration.