Hello everyone!
I am new to Julia and I am writing a simple simulation that uses a cartesian grid and numerical derivatives. I would like to confirm if my thinking is correct.
I start by defining simple grids for X, Y and a scalar field f which in this case is just Y.
n = 3
X = ones(Float64, n) * collect(1:n)'
Y = collect(1:n) * ones(Float64, n)'
f = Y
f is what I would expect:
3×3 Matrix{Float64}:
1.0 1.0 1.0
2.0 2.0 2.0
3.0 3.0 3.0
That is, f[3,1] #=> 3
I also define a simple gradient function:
function ∇(q::Matrix{Float64})
∇q_x = zeros(n,n)
∇q_y = zeros(n,n)
for j in 2:n-1, i in 2:n-1
∇q_x[i,j] = (q[i,j+1] - q[i,j-1])/2
∇q_y[i,j] = (q[i+1,j] - q[i-1,j])/2
end
Dict(:x => ∇q_x, :y => ∇q_y)
end
Is it correct to think of the first index (i
) as the y direction, and the second index (j
) as the x direction? That feels odd to me.
I understand it may just be a matter of convention, but when I try to visualize it, it does appear that Julia prefers it that way.
using Plots; gr()
heatmap(f, c=:blues)
quiver!(X, Y, quiver=(∇(f)[:x], ∇(f)[:y]), c=:white, linewidth=5)
Any thoughts are greatly appreciated!