Replacing normal arrays with static arrays

SMatrix is immutable, but you can use MMatrix like this:

julia> function euler(φ, θ, ψ)
           R = MMatrix{3,3,Float64}(undef)
           cosφ = cos(φ); cosψ = cos(ψ); cosθ = cos(θ)
           sinφ = sin(φ); sinψ = sin(ψ); sinθ = sin(θ)

           R[1,1] = cosφ*cosθ*cosψ - sinφ*sinψ
           R[1,2] = sinφ*cosθ*cosψ + cosφ*sinψ
           R[1,3] = -sinθ*cosψ

           R[2,1] = -cosφ*cosθ*sinψ - sinφ*cosψ
           R[2,2] = -sinφ*cosθ*sinψ + cosφ*cosψ
           R[2,3] = sinθ*sinψ

           R[3,1] = cosφ*sinθ
           R[3,2] = sinφ*sinθ
           R[3,3] = cosθ

           return SMatrix(R)
       end
1 Like