Reputation: 97
I want to use Julia to calculate the Euclidean distance between points (x(i), y(i)) and (x(j),y(j)), and I use the following codes
C = zeros(Float64,10,10)
x = [0.0, 20.0, 18.0, 30.0, 35.0, 33.0, 5.0, 5.0, 11.0, 2.0]
y = [0.0, 20.0, 10.0 ,12.0 ,0.0 ,25.0 ,27.0 ,10.0 ,0.0 ,15.0]
Required = [10.0, 6.0 ,8.0 ,11.0 ,9.0 ,7.0 ,15.0 ,7.0 ,9.0 ,12.0]
Present = [8.0, 13.0, 4.0, 8.0, 12.0, 2.0, 14.0, 11.0, 15.0, 7.0]
for i in 1:10
for j in 1:10
C[i,j] = 1.3*sqrt((x(i) - x(j))^2.0 + (y(i) - y(j))^2.0)
end
end
And the Julia gives me the following result
eLoadError: MethodError: `call` has no method matching call(::Array{Float64,1}, ::Int64)
Closest candidates are:
BoundsError()
BoundsError(!Matched::Any...)
DivideError()
...
while loading In[17], in expression starting on line 7
[inlined code] from In[17]:9
in anonymous at no file:0
Can anyone solve my problem? Thanks!
Upvotes: 2
Views: 952
Reputation: 3207
Rakesh is correct. Additionally, the reason the error message looks like that is that it's possible to overload the f( ... )
function call syntax, so it thinks you're trying to "call" the array and says there is no matching definition of call.
Upvotes: 1
Reputation: 587
Use x[i]
in stead of x(i)
etc.
The latter is Matlab syntax, it does not work in Julia.
Upvotes: 1