---
# System prepended metadata

title: CVX(matlab) syntax note
tags: [Math, matlab]

---

CVX(matlab) syntax note
===
###### tags: `Math` `matlab`

* cvx relies on external solver to solve problems.
    * ex: Mosek, Gurobi, SDTP3, SeDuMi
    * note: Mosek can solve MISOC-problem, while Gurobi cannot.(in 2, 3 years ago.)
* CVX's DCP ruleset is **sufficient** to check if a problem is convex or not, but **not necessary**.


## cvx variables
* `cvx_optval`: the optimal solution of the objective function, should be a number.
* `cvx_status`: the solver status.
    * ex: Solved, Unbouned, Infeasible....
    * note: Infeasible appears very often when the DCP rules is violated.
* `cvx_where`: the path of the cvx directory.
* `cvx_begin ... cvx_end`: the problem should be declared in this block.
* `cvx_begin quiet`: ask cvx to be quiet.
* `cvx_begin sdp`: tell cvx the following problem is a semidefinite problem.

## quick start examples
### 1. LP problem
$$
\max\ c^Tx \\ 
\text{s.t.}\ Ax<=b \\
x >= 0
$$

- in cvx:
    - ```=
        cvx_begin
            variable x(n)
            maximize (c’ * x)
            subject to
            A * x <= b
            x >= 0
        cvx_end
      ```
- w/o CVX:
    - `linprog(c, A, b, [], [], zeros(n,1), zeros(n,1)+Inf)`















