2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,10 +1,57 @@
a <- c( 3.0, 4.0, 5.0)
b <- c( 4.0, 3.0, 5.0)
#===============================================================
# Vector products
# R implementation
#===============================================================
cross <- function(a, b)
c(a[2]*b[3] - a[3]*b[2],
a[3]*b[1] - a[1]*b[3],
a[1]*b[2] - a[2]*b[1])
a <- c(3, 4, 5)
b <- c(4, 3, 5)
c <- c(-5, -12, -13)
cross(a, b)
# [1] 5 5 -7
#---------------------------------------------------------------
# Dot product
#---------------------------------------------------------------
dotp <- function(x, y) {
if (length(x) == length(y)) {
sum(x*y)
}
}
#---------------------------------------------------------------
# Cross product
#---------------------------------------------------------------
crossp <- function(x, y) {
if (length(x) == 3 && length(y) == 3) {
c(x[2]*y[3] - x[3]*y[2], x[3]*y[1] - x[1]*y[3], x[1]*y[2] - x[2]*y[1])
}
}
#---------------------------------------------------------------
# Scalar triple product
#---------------------------------------------------------------
scalartriplep <- function(x, y, z) {
if (length(x) == 3 && length(y) == 3 && length(z) == 3) {
dotp(x, crossp(y, z))
}
}
#---------------------------------------------------------------
# Vector triple product
#---------------------------------------------------------------
vectortriplep <- function(x, y, z) {
if (length(x) == 3 && length(y) == 3 && length(z) == 3) {
crosssp(x, crossp(y, z))
}
}
#---------------------------------------------------------------
# Compute and print
#---------------------------------------------------------------
cat("a . b =", dotp(a, b))
cat("a x b =", crossp(a, b))
cat("a . (b x c) =", scalartriplep(a, b, c))
cat("a x (b x c) =", vectortriplep(a, b, c))