# Objective function error in a robust model

**URL:** <https://discourse.julialang.org/t/objective-function-error-in-a-robust-model/49123>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [October 27, 2020, 2:43pm UTC](https://discourse.julialang.org/t/objective-function-error-in-a-robust-model/49123 "2020-10-27T14:43:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)\
**Post date:** [October 27, 2020, 2:43pm UTC](https://discourse.julialang.org/t/objective-function-error-in-a-robust-model/49123/1 "2020-10-27T14:43:54Z")

</div>

I need to put this objective function in Julia. Can someone help me?  
 ![F.O](https://global.discourse-cdn.com/julialang/original/3X/f/1/f1128a5bb47cc52f453a517899527e3407f98ea6.png)

I started doing this, but I still couldn’t compile the objective function

```julia
using JuMP, JuMPeR, DataFrames, MathOptInterface, GLPKMathProgInterface
ModelRobust = RobustModel(solver = GLPKSolverLP())

a = 1:4
t = 1:4
w = 1:2

A = a 
T = t 
W = w 

#Parameter
QD = [878 0; 0 1131; 100 0; 0 200]

@variable(ModelRobust,x[A,T]<=0)
@variable(ModelRobust,k[A,T]<=0)
@objective(ModelRobust,Max,sum(QD[a,w]*x[a,t]*k[a,t] for a in A))

```

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [October 27, 2020, 4:25pm UTC](https://discourse.julialang.org/t/objective-function-error-in-a-robust-model/49123/2 "2020-10-27T16:25:31Z")

</div>

> [@RaquelSantos](#):
>
> `sum(QD[a,w]*x[a,t]*k[a,t] for a in A)`

Hi!

I have never used JuMP, but if I am not missing something, the variable `w` is not defined in that sum when you are declaring the objective function. Is that correct?

---

<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:** [October 27, 2020, 7:29pm UTC](https://discourse.julialang.org/t/objective-function-error-in-a-robust-model/49123/3 "2020-10-27T19:29:42Z")

</div>

This is similar to a number of your [previous](https://discourse.julialang.org/t/how-to-use-the-summation-in-julia/41522) [questions](https://discourse.julialang.org/t/how-to-build-a-constraint-with-summation/41618/9).

Your (math) objective function doesn’t make sense because `w` and `t` are not defined.

In code, you need your summation to loop over all the indices, something like `for a in A, w in W, t in T`.
