Anonymous user
Vector products: Difference between revisions
Refactored code
No edit summary |
(Refactored code) |
||
Line 1,721:
=={{header|Julia}}==
{{works with|Julia|0.6}}
Julia provides dot and cross products as built-ins. It's easy enough to use these to construct the triple products.
<lang julia>function scalarproduct(a::AbstractVector{T}, b::AbstractVector{T}, c::AbstractVector{T}) where {T<:Number}
return dot(a, cross(b, c))▼
▲ dot(a, cross(b, c))
end
function vectorproduct(a::AbstractVector{T}, b::AbstractVector{T}, c::AbstractVector{T}) where {T<:Number}
return cross(a, cross(b, c))▼
▲ cross(a, cross(b, c))
end
const a = [3, 4, 5]
const b = [4, 3, 5]
const c = [-5, -12, -13]
println("Test Vectors:")
@show a b c
println("\nVector Products:")
@show scalarproduct(a, b, c)
@show vectorproduct(a, b, c)</lang>
{{out}}
<pre>Test Vectors:
▲ c = [3,4,5]
Vector Products:
=={{header|Kotlin}}==
|