I want to create a two dimensional array of 2D vectors (to represent a vector field).
My code is something like this
N=10
dx=1/(N-1)
dy=1/(N-1)
#initial data
U=fill(zeros(2), (N, N))
for i=1:1:N
for j=1:1:N
U[i,j][1]=(i-1)*dx
U[i,j][2]=(j-1)*dy
end
end
print(U[5, 7])
The result is [1.0, 1.0], which is not what I want. I have no idea why. However, if I change the code to something like this
N=10
dx=1/(N-1)
dy=1/(N-1)
#initial data
U=fill(zeros(2), (N, N))
for i=1:1:N
for j=1:1:N
U[i,j]=[(i-1)*dx, (i-1)*dx]
end
end
print(U[5, 7])
Then it print out the correct result, which is [0.4444444444444444, 0.6666666666666666]. So, what going on?