Skip to main content
edited body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

Matlab, 33 42 33 bytes

Using an anonymous function:

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

Input and output are matrices (2D numeric arrays).

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)round(inv(A+eps)'*det(A+eps))
ans = 
    @(A)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)round(inv(A+eps)'*det(A+eps))
ans = 
    @(A)round(inv(A+eps)*det(A+eps)')
>> ans([1,0 ; 0,0])
ans =
     0     0
     0     1

Or try it online in Octave.

Matlab, 33 42 bytes

Using an anonymous function:

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

Input and output are matrices (2D numeric arrays).

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)round(inv(A+eps)'*det(A+eps))
ans = 
    @(A)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)round(inv(A+eps)'*det(A+eps))
ans = 
    @(A)round(inv(A+eps)*det(A+eps)')
>> ans([1,0 ; 0,0])
ans =
     0     0
     0     1

Or try it online in Octave.

Matlab, 42 33 bytes

Using an anonymous function:

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

Input and output are matrices (2D numeric arrays).

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)round(inv(A+eps)'*det(A+eps))
ans = 
    @(A)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)round(inv(A+eps)'*det(A+eps))
ans = 
    @(A)round(inv(A+eps)*det(A+eps)')
>> ans([1,0 ; 0,0])
ans =
     0     0
     0     1

Or try it online in Octave.

As per the OP's clarifications, `mat2str` is not needed
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

Matlab, 4233 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 afteroutput are matrices ; can be removed(2D numeric arrays).

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    4
18    12    -6;6
-4    -1 2]    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]   0     0
     0     1

Or try it onlinetry it online in Octave.

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.

Matlab, 33 42 bytes

Using an anonymous function:

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

Input and output are matrices (2D numeric arrays).

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)round(inv(A+eps)'*det(A+eps))
ans = 
    @(A)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)round(inv(A+eps)'*det(A+eps))
ans = 
    @(A)round(inv(A+eps)*det(A+eps)')
>> ans([1,0 ; 0,0])
ans =
     0     0
     0     1

Or try it online in Octave.

edited body
Source Link
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 onlinetry it online in Octave.

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.

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.

edited body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372
Loading
added 370 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372
Loading
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372
Loading