How to build a constraint with summation?

The issue is that

julia> Q = [8780; 11310; 8600; 12500; 925; 1918; 4026; 5076]
8-element Array{Int64,1}:
  8780
 11310
  8600
 12500
   925
  1918
  4026
  5076

julia> Q[1, 5]
ERROR: BoundsError: attempt to access 8-element Array{Int64,1} at index [1, 5]
Stacktrace:
 [1] getindex(::Array{Int64,1}, ::Int64, ::Int64) at ./array.jl:745
 [2] top-level scope at REPL[2]:1

Q is a vector with one dimension of length 8:

julia> size(Q)
(8,)

You can index it Q[5, 1] (fifth row, first column), but not Q[1, 5] (first row, fifth column).

Here is the Julia documentation for arrays: Multi-dimensional Arrays · The Julia Language

1 Like