# Help with JuMP syntax for objective function

**URL:** https://discourse.julialang.org/t/help-with-jump-syntax-for-objective-function/62934
**Category:** Optimization (Mathematical)
**Tags:** jump, optimization
**Created:** [June 15, 2021, 9:33am UTC](https://discourse.julialang.org/t/help-with-jump-syntax-for-objective-function/62934 "2021-06-15T09:33:08Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Thomas](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@Thomas](https://discourse.julialang.org/u/Thomas)
#### Post date: [June 15, 2021, 9:33am UTC](https://discourse.julialang.org/t/help-with-jump-syntax-for-objective-function/62934/1 "2021-06-15T09:33:08Z")

</div>

When creating a model to solve SDP

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

```

I got an error

```julia
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 LinearAlgebra.dot) 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?

---

<div class="post-metadata">

### Author: ![hdavid16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hdavid16/32/11531_2.png) [@hdavid16](https://discourse.julialang.org/u/hdavid16)
#### Post date: [June 15, 2021, 10:04am UTC](https://discourse.julialang.org/t/help-with-jump-syntax-for-objective-function/62934/2 "2021-06-15T10:04:46Z")

</div>

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

[Linear Algebra · The Julia Language](https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/#LinearAlgebra.dot)

---

<div class="post-metadata">

### Author: ![Thomas](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@Thomas](https://discourse.julialang.org/u/Thomas)
#### Post date: [June 15, 2021, 10:29am UTC](https://discourse.julialang.org/t/help-with-jump-syntax-for-objective-function/62934/3 "2021-06-15T10:29:42Z")

</div>

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