I have a function that computes the unit vector and replaces the input with that unit vector. However, when I have the input as part of a larger array, it doesn't replace that part of the array.
For example, if the vector I want to make a unit vector is R = [1. 2.; 3. 4.; 5. 6.], the function unit!(R[:,1]) (listed below) should replace the first column of R with its unit vector. The current code is not. What am I doing wrong? Thanks for the help! function unit!{T}(V::AbstractArray{T}) v=mag(V) for ii in 1:3 V[ii] = V[ii]/v end if v == 0 V[1] = 1 V[2] = 0 V[3] = 0 end #no divide by 0 return v end function mag{T}(R::AbstractArray{T}) R=sqrt(dot(R,R)) end