R/vandermode.R

#' Vandermode Matrix
#'
#' The function returns the Vandermode matrix of a numeric vector, \code{x}, whose columns are the vector
#' raised to the powers \code{0:n}.
#'
#' @param x a numeric vector
#' @param n a numeric scalar
#'
#' @return a matrix of size \code{length(x)} x \code{n}
#'
#' @export
#' @examples
#' vandermode(1:5, 4)
vandermode <- function (x, n) {
  if (!is.vector(x))
    stop("argument x is not a vector")
  if (!is.numeric(n))
    stop("argument n is not a numeric scalar")

  outer(x, 0:(n-1), "^")
}

Try the matlib package in your browser

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

matlib documentation built on Dec. 9, 2022, 1:09 a.m.