R/new_baseb_expansion.R

Defines functions new_baseb_expansion

Documented in new_baseb_expansion

#' Creates a new base-b sequence of a designated length
#'
#' @param k The integer to expand
#' @param b Base for integer expansions used in the sequence
#' @return The expansion of the integer k
#' @import pracma

new_baseb_expansion <- function(k, b) {
  if (k > 0) {
    jmax <- trunc(mrdivide(log(k) , log(b)))
    a <- matrix(0, 1, jmax + 1)
    q <- b ^ jmax
    for (j in 1:(jmax + 1)) {
      a[j] <- floor(mrdivide(k , q))
      k <- k - q %*% a[j]
      q <- mrdivide(q,b)
    }
  } else {
    a <- matrix(0, 1, 1)
  }
  return(a)
}

Try the SyScSelection package in your browser

Any scripts or data that you put into this service are public.

SyScSelection documentation built on Oct. 26, 2020, 5:08 p.m.