Hi there, I am newbie to Julia.
I am learning Julia, and so I want to create a simple function to convert a set of coordinates from cartesian to polar, and backwards. This is a trivial task, but I am stuck on the correct syntaxis for the atan
function to be general to accept a value, and an array.
I run easily atan
with two float numbers (e.g., atan(2.,4.)
). However, I want to be able to pass also a vector (Array{Float64,1}), matrix of complex numbers, etc. It could be broadcasting but I do not get the right syntax.
function cart2pol(x,y,z)
theta = atan(y,x)
rho = sqrt(x*x + y*y)
return theta, rho, z
end
x = [1,2.1213,0,-5]
y = [0,2.1213,4,0]
z = [7.,8,9,10]
theta,rho,z = cart2pol(x,y,z)
However, I get the following error.
MethodError: no method matching atan(::Array{Float64,1}, ::Array{Float64,1})
Stacktrace:
[1] cart2pol(::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}) at .\In[24]:4
[2] top-level scope at In[26]:1
Any help will be appreaciated (solution or point to the right section in the manual to understand it)