Quaternion type: Difference between revisions
Content added Content deleted
(added Julia example) |
|||
Line 2,777: | Line 2,777: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
This is from the quaternion example file included with Julia 0.2 which implements a quaternion type complete with arithmetic, type conversions and promotion rules, and pretty-printing: |
This is from the [https://github.com/JuliaLang/julia/blob/master/examples/quaternion.jl quaternion example file] included with Julia 0.2, which implements a quaternion type complete with arithmetic, type conversions and promotion rules, and pretty-printing: |
||
<lang julia>import Base: promote_rule, convert |
<lang julia>import Base: promote_rule, convert |
||
Line 2,857: | Line 2,857: | ||
Example usage and output: <lang julia>julia> q = Quaternion(1,0,0,0) |
Example usage and output: <lang julia>julia> q = Quaternion(1,0,0,0) |
||
julia> |
julia> q = Quaternion (1, 2, 3, 4) |
||
q1 = Quaternion(2, 3, 4, 5) |
|||
q2 = Quaternion(3, 4, 5, 6) |
|||
r = 7. |
|||
julia> |
julia> norm(q) |
||
5.477225575051661 |
|||
println("q*2.0+2 = $(q*2.0+2)") |
|||
println("abs((-q+x*2)/4) = ", abs((-q+x*2)/4)) |
|||
julia> -q |
|||
⚫ | |||
-1 - 2i - 3j - 4k |
|||
⚫ | |||
abs((-q+x*2)/4) = 0.9013878188659973</lang> |
|||
julia> conj(q) |
|||
1 - 2i - 3j - 4k |
|||
julia> r + q, q + r |
|||
⚫ | |||
julia> q1 + q2 |
|||
⚫ | |||
julia> r*q, q*r |
|||
(7.0 + 14.0i + 21.0j + 28.0k,7.0 + 14.0i + 21.0j + 28.0k) |
|||
julia> q1*q2, q2*q1, q1*q2 != q2*q1 |
|||
(-56 + 16i + 24j + 26k,-56 + 18i + 20j + 28k,true)</lang> |
|||
=={{header|Liberty BASIC}}== |
=={{header|Liberty BASIC}}== |