Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
determinant calculation of integer matrices

Subject: determinant calculation of integer matrices

From: Matt J

Date: 1 Apr, 2013 16:32:18

Message: 1 of 8

P=magic(9)-41 is a matrix of integers. You would therefore expect its determinant, whose calculation involves just products and sums of the P(i,j), to result in an integer as well. However, I get a non-integer result

>> det(P)

ans =

   -0.3211


How does one rationalize this?

Subject: determinant calculation of integer matrices

From: Bruno Luong

Date: 1 Apr, 2013 16:48:10

Message: 2 of 8

"Matt J" wrote in message <kjccqi$aje$1@newscl01ah.mathworks.com>...
> P=magic(9)-41 is a matrix of integers. You would therefore expect its determinant, whose calculation involves just products and sums of the P(i,j), to result in an integer as well. However, I get a non-integer result
>
> >> det(P)
>
> ans =
>
> -0.3211
>
>
> How does one rationalize this?

MATLAB determinant use LU factorization.

Bruno

Subject: determinant calculation of integer matrices

From: Matt J

Date: 1 Apr, 2013 16:59:14

Message: 3 of 8

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kjcdoa$dh8$1@newscl01ah.mathworks.com>...
>
> MATLAB determinant use LU factorization.
======

Is there a reason that's supposed to be better than co-factor expansion? In the case of P=magic(9)-41 one can see that a significant absolute error is obtained through LU, whereas with co-factor expansion, you would have none.

Subject: determinant calculation of integer matrices

From: Bruno Luong

Date: 1 Apr, 2013 17:22:06

Message: 4 of 8

> Is there a reason that's supposed to be better than co-factor expansion? In the case of P=magic(9)-41 one can see that a significant absolute error is obtained through LU, whereas with co-factor expansion, you would have none.

Complexity.

When one is dealing with ill-conditioned (or not) matrix, asking for numerical determinant is generally useless in practice.

The co-factor method also requires high numerical precision that is also has its limitation without infinity precision numbers, especially for large dimension.

Bruno

Subject: determinant calculation of integer matrices

From: Bruno Luong

Date: 4 Apr, 2013 19:49:06

Message: 5 of 8

Someone asks me off line why det (magic(9) - 41) = 0. Here is how I see it:

It is easy to check sum( magic(9) ) / 9 = 41

Thus
sum(magic(9) - 41) = 0.

That means

(magic(9) - 41) * ones(9,1) = 0.

Therefore A = (magic(9) - 41) is not full rank (because A*x = 0 has non trivial solution).

So det (magic(9) - 41) = 0.

Bruno

Subject: determinant calculation of integer matrices

From: Bruno Luong

Date: 4 Apr, 2013 19:51:06

Message: 6 of 8

In the same way

det(magic(2013)-2026085) = 0

Bruno

Subject: determinant calculation of integer matrices

From: Bruno Luong

Date: 4 Apr, 2013 20:16:19

Message: 7 of 8

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kjklja$j3n$1@newscl01ah.mathworks.com>...
> In the same way
>
> det(magic(2013)-2026085) = 0
>
> Bruno

Note that as

magic(N) has elements the permutation of { 1, 2, ... N^2 }. Sum of consecutive series formula gives this identity:

sum(sum(magic(N))) = sum { 1, 2, ... N^2 } = (N^2 + 1) * N^2 /2.

Therefore sum(magic(N)) / N = (N^2 + 1) / 2.

In other word det( magic(N) - (N^2 + 1) /2) = 0 for all N.

Bruno

Subject: determinant calculation of integer matrices

From: Steven_Lord

Date: 5 Apr, 2013 14:50:19

Message: 8 of 8



"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message
news:kjklfi$il6$1@newscl01ah.mathworks.com...
> Someone asks me off line why det (magic(9) - 41) = 0. Here is how I see
> it:
>
> It is easy to check sum( magic(9) ) / 9 = 41
>
> Thus
> sum(magic(9) - 41) = 0.
>
> That means
>
> (magic(9) - 41) * ones(9,1) = 0.
>
> Therefore A = (magic(9) - 41) is not full rank (because A*x = 0 has non
> trivial solution).
>
> So det (magic(9) - 41) = 0.

Taking this a little further aside, if you want to tell if a matrix is
singular or not, do NOT use DET.

% Sample matrix
A = 0.1*eye(400);

d = det(A)
% Since this is 0, A is singular! Right???

c = cond(A)
% But it's well conditioned!

s = svd(A);
ms = max(abs(s-0.1))
% All singular values are extremely close to 0.1. That's good, right?

x = rand(400, 1);
y = A\x;
% MATLAB has no problem solving this system

n = norm(A*y-x)
% The residual norm should be very small which is another good sign.
% How do we reconcile this with the fact that DET told us A is singular?

Use COND or RCOND for singularity checking instead.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us