Vector products: Difference between revisions
Content added Content deleted
No edit summary |
(Refactored code) |
||
Line 1,721: | Line 1,721: | ||
=={{header|Julia}}== |
=={{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. |
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} |
|||
<lang Julia> |
|||
⚫ | |||
function scltrip{T<:Number}(a::AbstractArray{T,1}, |
|||
b::AbstractArray{T,1}, |
|||
c::AbstractArray{T,1}) |
|||
⚫ | |||
end |
end |
||
function vectorproduct(a::AbstractVector{T}, b::AbstractVector{T}, c::AbstractVector{T}) where {T<:Number} |
|||
function vectrip{T<:Number}(a::AbstractArray{T,1}, |
|||
⚫ | |||
b::AbstractArray{T,1}, |
|||
c::AbstractArray{T,1}) |
|||
⚫ | |||
end |
end |
||
a = [3, 4, 5] |
const a = [3, 4, 5] |
||
b = [4, 3, 5] |
const b = [4, 3, 5] |
||
c = [-5, -12, -13] |
const c = [-5, -12, -13] |
||
println("Test Vectors:") |
println("Test Vectors:") |
||
@show a b c |
|||
println(" a = ", a) |
|||
println(" b = ", a) |
|||
println(" c = ", a) |
|||
println("\nVector Products:") |
println("\nVector Products:") |
||
@show dot(a, b) |
|||
@show cross(a, b) |
|||
@show scalarproduct(a, b, c) |
|||
println(" a dot b cross c = ", scltrip(a, b, c)) |
|||
@show vectorproduct(a, b, c)</lang> |
|||
println(" a cross b cross c = ", vectrip(a, b, c)) |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre>Test Vectors: |
||
⚫ | |||
Test Vectors: |
|||
b = [4, 3, 5] |
|||
c = [-5, -12, -13] |
|||
⚫ | |||
Vector Products: |
Vector Products: |
||
dot(a, b) = 49 |
|||
cross(a, b) = [5, 5, -7] |
|||
scalarproduct(a, b, c) = 6 |
|||
vectorproduct(a, b, c) = [-267, 204, -3]</pre> |
|||
</pre> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |