Revision 03698027c2d84118bd0c53c4a9a5b5d23676f388 authored by HwB on 01 October 2012, 00:00:00 UTC, committed by Gabor Csardi on 01 October 2012, 00:00:00 UTC
1 parent 9fdea5d
Raw File
mldivide.R
##
##  m l d i v i d e . R  Matlab backslash Operator
##


mldivide <- function(A, B) {
    stopifnot(is.numeric(A) || is.complex(A),
              is.numeric(B) || is.complex(B))
    if (is.vector(A)) A <- as.matrix(A)
    if (is.vector(B)) B <- as.matrix(B)
    if (nrow(A) != nrow(A))
        stop("Matrices 'A' and 'B' must have the same number of rows.")

    qr.solve(A, B)
}

mrdivide <- function(A, B) {
    stopifnot(is.numeric(A) || is.complex(A),
              is.numeric(B) || is.complex(B))
    if (is.vector(A)) A <- t(A)
    if (is.vector(B)) B <- t(B)
    if (ncol(A) != ncol(A))
        stop("Matrices 'A' and 'B' must have the same number of columns.")

    t(mldivide(t(B), t(A)))
}
back to top