How to code lattice closest vector problem

Thank you so much!

Have you read the CVX Users’ Guide ? 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

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

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