Vector products: Difference between revisions

→‎{{header|Ruby}}: Removed Vector#cross_product (built in since Ruby 2.1)
(→‎{{header|Ruby}}: Removed Vector#cross_product (built in since Ruby 2.1))
Line 2,788:
 
=={{header|Ruby}}==
Dot product is also known as ''inner product''. The standard library already defines Vector#inner_product and Vector# cross_product, so this program only defines the other threetwo methods.
<lang ruby>require 'matrix'
 
class Vector
def cross_product(v)
unless size == 3 && v.size == 3
raise ArgumentError, "Vectors must have size 3"
end
Vector[self[1] * v[2] - self[2] * v[1],
self[2] * v[0] - self[0] * v[2],
self[0] * v[1] - self[1] * v[0]]
end
 
def scalar_triple_product(b, c)
self.inner_product(b.cross_product c)
1,149

edits