Skip to main content
4 of 6
edited body
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

Matlab, 42 bytes

Using an anonymous function:

@(A)mat2str(round(inv(A+eps)'*det(A+eps)))

Input is in standard Matlab format, that is, [-3,2,-5; -1,0,-2; 3,-4,1], where commas can be replaced by spaces, and spaces after ; can be removed.

eps is added in case the matrix is singular. It is "removed" using round (the true result is guaranteed to be an integer).

Example:

>> @(A)mat2str(round(inv(A+eps)'*det(A+eps)))
ans = 
    @(A)mat2str(round(inv(A+eps)'*det(A+eps)))
>> ans([-3,2,-5; -1,0,-2; 3,-4,1])
ans =
[-8 -5 4;18 12 -6;-4 -1 2]

Example with singular matrix:

>> @(A)mat2str(round(inv(A+eps)'*det(A+eps)))
ans = 
    @(A)mat2str(round(inv(A+eps)*det(A+eps)'))
>> ans([1,0 ; 0,0])
ans =
[0 0;0 1]

Or try it online in Octave.

Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372