# What does this error message mean? From Convex.jl: Cannot \`convert\` an object of type EqConstraint

**URL:** https://discourse.julialang.org/t/what-does-this-error-message-mean-from-convex-jl-cannot-convert-an-object-of-type-eqconstraint/34384
**Category:** General Usage
**Created:** [February 9, 2020, 8:28pm UTC](https://discourse.julialang.org/t/what-does-this-error-message-mean-from-convex-jl-cannot-convert-an-object-of-type-eqconstraint/34384 "2020-02-09T20:28:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kai](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@kai](https://discourse.julialang.org/u/kai)
#### Post date: [February 9, 2020, 8:28pm UTC](https://discourse.julialang.org/t/what-does-this-error-message-mean-from-convex-jl-cannot-convert-an-object-of-type-eqconstraint/34384/1 "2020-02-09T20:28:21Z")

</div>

Hi, I ran into the following error and could not find help from reading the documentation.

The error is

```julia
MethodError: Cannot `convert` an object of type EqConstraint to an object of type Array{Constraint,N} where N

```

My code is:

```julia
h = 1.
g = 0.1
m = 10.
Fmax = 10.
p0 = [50, 50, 100]
v0 = [-10, 0, -10]
alpha = 0.5
gamma = 1.
K = 35;
using Convex, Mosek
solver = MosekSolver()
p = Variable(3, K+1)
v = Variable(3, K+1)
f = Variable(3, K)
problem = minimize(sum(gamma .* [Convex.norm(f[:, i]) for i in 1:K])) 
constraint1 = p[:, 1] == p0
constraint2 = p[:, K+1] == zeros(3)
constraint3 = v[:, 1] == v0
constraint4 = v[:, K+1] == zeros(3)
constraint5 = p[:, 2:(K+1)] == p[:, 1:K] + (h / 2) * (v[:, 1:K] + v[:, 2:(K+1)])
constraint6 = v[:, 2:(K+1)] == v[:, 1:K] + (h / m) .* f[:, 1:K] - (h * g) .* transpose(repeat([0 0 1], K))
constraint7 = [Convex.norm(f[:, i]) for i in 1:K] .≤ Fmax .* ones(K)
constraint8 = [p[3, i] ≥ alpha * Convex.norm(p[1:2, i]) for i in 1:(K+1)]
problem.constraints = constraint1
problem.constraints += [
    constraint2, constraint3, constraint4, 
    constraint5, constraint6, constraint7, constraint8
]
solve!(problem, solver)

```

---

<div class="post-metadata">

### Author: ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)
#### Post date: [February 9, 2020, 9:03pm UTC](https://discourse.julialang.org/t/what-does-this-error-message-mean-from-convex-jl-cannot-convert-an-object-of-type-eqconstraint/34384/2 "2020-02-09T21:03:57Z")

</div>

I think the issue is that some of those are individual constraints, and others are vectors of constraints. I usually do something like

```julia
constrs = Constraint[] # initialize a vector of constraints
push!(constrs, x >= 0) # add a single constraint
append!(constrs, vector_of_constraints) # add a vector of constraints
...
problem = minimize(objective, constrs)

```

Of course, you can do `append!(problem.constraints, vector_of_constraints)` too, or populate them in a loop, etc.

By the way, I am thinking we should remove the overload for `problem.constraints += constraint` because I think it’s nicer if move towards treating Convex.jl objects more like regular Julia objects, and stick to the usual ways of populating vectors etc.

---

<div class="post-metadata">

### Author: ![kai](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@kai](https://discourse.julialang.org/u/kai)
#### Post date: [February 9, 2020, 10:50pm UTC](https://discourse.julialang.org/t/what-does-this-error-message-mean-from-convex-jl-cannot-convert-an-object-of-type-eqconstraint/34384/3 "2020-02-09T22:50:19Z")

</div>

> [@ericphanson](#):
>
> push!(constrs, x \>= 0) # add a single constraint append!(constrs, vector\_of\_constraints)

Thank you very much! This solves my problem.
