Reputation: 743
would you please help me how can I solve the undefined var error in the following code:
Beta
6×3×3 Array{Array{Int64,1},3}:
[:, :, 1] =
[4, 2, 5, 3, 6] [4, 2, 5, 3, 6] [4, 2, 5, 3, 6]
[5, 3, 6] [5, 3, 6] [5, 3, 6]
[6] [6] [6]
[2, 5, 3, 6] [2, 5, 3, 6] [2, 5, 3, 6]
[3, 6] [3, 6] [3, 6]
[1, 4, 2, 5, 3] [1, 4, 2, 5, 3] [1, 4, 2, 5, 3]
[:, :, 2] =
[4, 2, 5, 3, 6] [4, 2, 5, 3, 6] [4, 2, 5, 3, 6]
[5, 3, 6] [5, 3, 6] [5, 3, 6]
[6] [6] [6]
[2, 5, 3, 6] [2, 5, 3, 6] [2, 5, 3, 6]
[3, 6] [3, 6] [3, 6]
[1, 4, 2, 5, 3] [1, 4, 2, 5, 3] [1, 4, 2, 5, 3]
[:, :, 3] =
[4, 2, 5, 3, 6] [4, 2, 5, 3, 6] [4, 2, 5, 3, 6]
[5, 3, 6] [5, 3, 6] [5, 3, 6]
[6] [6] [6]
[2, 5, 3, 6] [2, 5, 3, 6] [2, 5, 3, 6]
[3, 6] [3, 6] [3, 6]
[1, 4, 2, 5, 3] [1, 4, 2, 5, 3] [1, 4, 2, 5, 3]
Beta is an array matrix and d matrix as follow:
d=[ 0.0 105.0 119.0 55.0 123.0 44.0
105.0 0.0 76.0 135.0 42.0 81.0
119.0 76.0 0.0 170.0 42.0 76.0
55.0 135.0 170.0 0.0 164.0 97.0
123.0 42.0 42.0 164.0 0.0 86.0
44.0 81.0 76.0 97.0 86.0 0.0];
sum(d[i,j]*x[i,j,k,t] for i in 1:6,j in Set(Beta[i,k,t]), t in 1:3, k in 1:3 )
ERROR: UndefVarError: i not defined
Stacktrace:
[1] macro expansion at C:\Users\admin\AppData\Local\JuliaPro-0.6.4.
1\pkgs-0.6.4.1\v0.6\Atom\src\repl.jl:118 [inlined]
[2] anonymous at .\<missing>:?
why this error is happened? if you don't mind please help me about that error . thanks
Upvotes: 1
Views: 41
Reputation: 69869
The required functionality is explained in Generator Expressions section of the Julia manual:
Ranges in generators and comprehensions can depend on previous ranges by writing multiple for keywords:
julia> [(i,j) for i=1:3 for j=1:i]
6-element Array{Tuple{Int64,Int64},1}:
(1, 1)
(2, 1)
(2, 2)
(3, 1)
(3, 2)
(3, 3)
In such cases, the result is always 1-d.
Upvotes: 1