R/ortonormalBasis.R

Defines functions ortonormalBasis

Documented in ortonormalBasis

#' Gives us ortonomal basis
#'
#' Calculates a dot product between matrices
#'
#' @param x1 The first vector.
#' @param x2 The second vector.
#'
#' @return Should give us a number.
#' @export
ortonormalBasis <- function(x1,x2){

  x2x1 <- t(x1) %*% x2
  x1x1 <- t(x1) %*% x1

  v1 <- x1
  v2 <- x2 - drop(x2x1/x1x1) * x1

  norm_vec <- function(x) sqrt(sum(x^2))

  u1 <- drop(1/norm_vec(v1)) * v1
  u2 <- drop(1/norm_vec(v2)) * v2

  cbind(u1,u2)
}
lucasbagge/LinAlg4 documentation built on March 15, 2020, 6:43 a.m.