Help with JuMP syntax for objective function

When creating a model to solve SDP

@variable(model, X[1:n,1:n], PSD)
@constraint(model, A*vec(X).==b)
@objective(model, Min, c*vec(X))

I got an error

ERROR: MethodError: no method matching *(::SparseVector{Int64, Int64}, ::Base.ReshapedArray{VariableRef, 1, Symmetric{VariableRef, Matrix{VariableRef}}, Tuple{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64}}})

which basically says that I cannot multiply (as in a vector and another Array{VariableRef}.

A quick fix is sum(c.*vec(X)) but what is the correct way to write such objective function?

You can use @objective(model, Min, dot(c, vec(X)). You will need to load LinearAlgebra (using LinearAlgebra)

Linear Algebra · The Julia Language

1 Like

Thanks. So i made a basic mistake: Base.:* is not the same operator as (typeset with \cdot).

1 Like