Learn R Programming

matlib (version 0.9.6)

xprod: Generalized Vector Cross Product

Description

Given two linearly independent length 3 vectors **a** and **b**, the cross product, \(\mathbf{a} \times \mathbf{b}\) (read "a cross b"), is a vector that is perpendicular to both **a** and **b** thus normal to the plane containing them.

Usage

xprod(...)

Value

Returns the generalized vector cross-product, a vector of length N.

Arguments

...

N-1 linearly independent vectors of the same length, N.

Author

Matthew Lundberg, in a [Stack Overflow post][https://stackoverflow.com/questions/36798301/r-compute-cross-product-of-vectors-physics]

Details

A generalization of this idea applies to two or more dimensional vectors.

See: [https://en.wikipedia.org/wiki/Cross_product] for geometric and algebraic properties. Cross-product of 3D vectors

Examples

Run this code
xprod(1:3, 4:6)

# This works for an dimension
xprod(c(0,1))             # 2d
xprod(c(1,0,0), c(0,1,0)) # 3d
xprod(c(1,1,1), c(0,1,0)) # 3d
xprod(c(1,0,0,0), c(0,1,0,0), c(0,0,1,0)) # 4d

Run the code above in your browser using DataLab