Determinant and permanent: Difference between revisions

Content added Content deleted
(Added R.)
(→‎{{header|R}}: Simplified squareness check.)
Line 2,274: Line 2,274:
{
{
stopifnot(is.matrix(A))
stopifnot(is.matrix(A))
dimensions <- dim(A)
n <- nrow(A)
if(n != ncol(A)) stop("Matrix is not square.")
n <- dimensions[1]
if(any(dimensions != n)) stop("Matrix is not square.")
if(n < 1) stop("Matrix has a dimension of size 0.")
if(n < 1) stop("Matrix has a dimension of size 0.")
sum(sapply(combinat::permn(n), function(sigma) prod(sapply(1:n, function(i) A[i, sigma[i]]))))
sum(sapply(combinat::permn(n), function(sigma) prod(sapply(1:n, function(i) A[i, sigma[i]]))))