Determinant and permanent: Difference between revisions

→‎{{header|R}}: Simplified squareness check.
(Added R.)
(→‎{{header|R}}: Simplified squareness check.)
Line 2,274:
{
stopifnot(is.matrix(A))
dimensionsn <- dimnrow(A)
if(any(dimensionsn != nncol(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.")
sum(sapply(combinat::permn(n), function(sigma) prod(sapply(1:n, function(i) A[i, sigma[i]]))))
331

edits