Vector products: Difference between revisions

Content added Content deleted
(→‎{{header|Haskell}}: Added a variant based on Either and (>>=) rather than `error`)
No edit summary
Line 2,458: Line 2,458:
to_string(vector3d(X, Y, Z)) =
to_string(vector3d(X, Y, Z)) =
string.format("(%d, %d, %d)", [i(X), i(Y), i(Z)]).</lang>
string.format("(%d, %d, %d)", [i(X), i(Y), i(Z)]).</lang>

=={{header|MiniScript}}==
<lang MiniScript>vectorA = [3, 4, 5]
vectorB = [4, 3, 5]
vectorC = [-5, -12, -13]

dotProduct = function(x, y)
return x[0]*y[0] + x[1]*y[1] + x[2]*y[2]
end function

crossProduct = function(x, y)
return [x[1]*y[2] - x[2]*y[1], x[2]*y[0] - x[0]*y[2], x[0]*y[1] - x[1]*y[0]]
end function

print "Dot Product = " + dotProduct(vectorA, vectorB)
print "Cross Product = " + crossProduct(vectorA, vectorB)
print "Scalar Triple Product = " + dotProduct(vectorA, crossProduct(vectorB,vectorC))
print "Vector Triple Product = " + crossProduct(vectorA, crossProduct(vectorB,vectorC))
</lang>
{{out}}
<pre>
Dot Product = 49
Cross Product = [5, 5, -7]
Scalar Triple Product = 6
Vector Triple Product = [-267, 204, -3]
</pre>


=={{header|МК-61/52}}==
=={{header|МК-61/52}}==