R/eye.R

Defines functions zeros ones eye

Documented in eye ones zeros

##
##  e y e . R  Generate basic Matrices
##


eye <- function(n, m = n) {
    stopifnot(is.numeric(n), length(n) == 1,
              is.numeric(m), length(m) == 1)
    n <- floor(n)
    m <- floor(m)
    if (n <= 0 || m <= 0) return(matrix(NA, 0, 0))
    else                  return(base::diag(1, n, m))
}

ones <- function(n, m = n) {
        stopifnot(is.numeric(n), length(n) == 1,
                  is.numeric(m), length(m) == 1)
        n <- floor(n)
        m <- floor(m)
        if (n <= 0 || m <= 0) return(matrix(1, 0, 0))
        else                  return(matrix(1, n, m))
}

zeros <- function(n, m = n) {
    stopifnot(is.numeric(n), length(n) == 1,
              is.numeric(m), length(m) == 1)
    n <- floor(n)
    m <- floor(m)
    if (n <= 0 || m <= 0) return(matrix(0, 0, 0))
    else                  return(matrix(0, n, m))
}

Try the pracma package in your browser

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

pracma documentation built on March 19, 2024, 3:05 a.m.