# How do I write @variable(z=x\[1\]+x\[2\])?

**URL:** <https://discourse.julialang.org/t/how-do-i-write-variable-z-x-1-x-2/79149>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [April 7, 2022, 8:30am UTC](https://discourse.julialang.org/t/how-do-i-write-variable-z-x-1-x-2/79149 "2022-04-07T08:30:45Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [April 7, 2022, 8:53am UTC](https://discourse.julialang.org/t/how-do-i-write-variable-z-x-1-x-2/79149/2 "2022-04-07T08:53:04Z")

</div>

Hi there,

Since this is your first post, please read: [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757). It has some advice on how to write a good question.

I’m not entirely sure what you mean by an equality in the objective function, but here’s how I would write your model:

```julia
model = Model()
@variable(model, x[1:2] >= 0, Int)
@variable(model, z)
@constraint(model, z == x[1]) # Note sure which one of these you meant 
@constraint(model, z == 8x[1] + 5x[2]) # 
@constraint(model, 8x[1] + 1.5x[2] <= z)
@constraint(model, x[1] + x[2] <= 6)
@objective(model, Max, z)

```

If that isn’t helpful, perhaps you could explain in a bit more detail what you’re trying to achieve?

---

_[View the full topic](https://discourse.julialang.org/t/how-do-i-write-variable-z-x-1-x-2/79149)._
