How to code lattice closest vector problem

Thank you so much!

Have you read the CVX Users’ Guide http://cvxr.com/cvx/doc/ ? This problem is almost as simple to enter as it gets in CVX.

There is no point in squaring the objective function, although you can do so using square_pos.

The simplest formulation (not squaring the norm in the objective function) is

cvx_begin
variable x(n) integer
minimize(norm(v - B*x))
cvx_end

Due to the integer constraint,.you will need to have available and use Gurobi or Mosek as solver,