maxsub finds a contiguous subarray whose sum is maximally positive. This is sometimes called Kadane's algorithm. maxsub will use a very fast version with a running time of O(n) where n is the length of the input vector x.
maxsub2d finds a (contiguous) submatrix whose sum of elements is maximally positive. The approach taken here is to apply the one-dimensional routine to summed arrays between all rows of A. This has a run-time of O(n^3), though a run-time of O(n^2 log n) seems possible see the reference below. maxsub2d can solve a 100-by-100 matrix in a few seconds -- but beware of bigger ones.
Returns
Either just a maximal sum, or a list this sum as component sum plus the start and end indices as a vector inds.
T. Takaoka (2002). Efficient Algorithms for the Maximum Subarray Problem by Distance Matrix Multiplication. The Australasian Theory Symposion, CATS 2002.
Note
In special cases, the matrix A may be sparse or (as in the example section) only have one nonzero element in each row and column. Expectation is that there may exists a more efficient (say O(n^2)) algorithm in these special cases.