Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I compute an adjunct matrix?

211 views
Skip to first unread message

David Scott

unread,
Oct 17, 2006, 12:48:38 PM10/17/06
to
How can I use Matlab to compute an adjunct matrix?

Here's an example from my Linear Algebra book:
A = [1 2 3
2 3 4
3 4 5]

From the answers in the back of the book, the adjunct matrix is,
adj A = [-1 2 -1
2 -4 2
-1 2 -1]

I've been using det(A) in Matlab to compute the determinant and check
my work. Is there a similar function to compute the adjunct matrix?

Greg von Winckel

unread,
Oct 17, 2006, 12:56:18 PM10/17/06
to
Hmm. I've never heard of an adjunct matrix before. Typically the
notation adj refers to the matrix adjoint.

In my experience, I have never actually needed the adjoint explicitly
for anything. It is computed from the determinants of all the minors
and is used in defining the matrix inverse (an object I have needed
explicitly only very rarely).

What are you trying to do that requires the adjoint?

-Greg

David Scott

unread,
Oct 17, 2006, 1:20:57 PM10/17/06
to
Thanks, I don't know how "adjunct" got stuck in my head. Still, I was
unable to find any functions in Matlab that would compute the adjoint
matrix.

I'm trying to check my Linear Algebra homework. ^_-

Greg von Winckel

unread,
Oct 17, 2006, 1:35:53 PM10/17/06
to
I see. I'd guess the reason there is not a Matlab function is that it
would really only be useful for checking linear algebra homework.

Since I'm feeling generous, here's an adjoint function:

function B=adj(A)

n=size(A,1); d=1:n-1;
B=zeros(n);

AA=[A,A;A,A]';

for j=1:n
for k=1:n
B(j,k)=(-1)^(j+k)*det(AA(j+d,k+d));
end
end

Don't use this for big matrices!

HTH,

Greg

Roger Stafford

unread,
Oct 17, 2006, 3:12:43 PM10/17/06
to
In article <ef43...@webcrossing.raydaftYaTP>, "Greg von Winckel"
<greg...@mathDEL.unmDEL.edu> wrote:

> I see. I'd guess the reason there is not a Matlab function is that it
> would really only be useful for checking linear algebra homework.
>
> Since I'm feeling generous, here's an adjoint function:
>
> function B=adj(A)
>
> n=size(A,1); d=1:n-1;
> B=zeros(n);
>
> AA=[A,A;A,A]';
>
> for j=1:n
> for k=1:n
> B(j,k)=(-1)^(j+k)*det(AA(j+d,k+d));
> end
> end
>
> Don't use this for big matrices!
>
> HTH,
>
> Greg

-----------------------
Greg, if you leave out the factor (-1)^(j+k), you'll have it right.

Roger Stafford

Greg von Winckel

unread,
Oct 17, 2006, 3:29:08 PM10/17/06
to
Doh! I'm not sure how I left that in there. Thanks, Roger. Here is
the correction:

function B=adj(A)

n=size(A,1); d=1:n-1;
B=zeros(n); AA=[A,A;A,A]';

for j=1:n
for k=1:n

B(j,k)=det(AA(j+d,k+d));
end
end

Still, let me re-emphasize that this is only useful as an educational
aid.

Jos

unread,
Oct 17, 2006, 3:57:34 PM10/17/06
to

The word adjoint is ambiguous. The above is also known as the
adjugate of matrix A. Formally, the adjoint is the same as the
conjugate transpose of A.

B = A.' ; % adjoint

B = det(A) * inv(A) ; % adjugate, for square invertible matrices

hth
Jos

Greg von Winckel

unread,
Oct 17, 2006, 4:14:37 PM10/17/06
to
That does seem a better name. Sadly it never came up in any of my
classes. "Adjoint" is ambiguous by itself, but usually pretty clear
from context. In most of my classes the conjugate transpose was
called "Hermitian conjugate" whereas the adjugate was only ever
mention in control systems classes, never in math classes.

Jos

unread,
Oct 17, 2006, 4:30:42 PM10/17/06
to
Jos wrote:
<SNIP ... adjoint adjugate

> B = A.' ; % adjoint

should be B = A' of course ...

Jos

David Scott

unread,
Oct 17, 2006, 6:14:51 PM10/17/06
to
> The word adjoint is ambiguous. The above is also known as the
> adjugate of matrix A. Formally, the adjoint is the same as the
> conjugate transpose of A.
>
> B = A.' ; % adjoint
>
> B = det(A) * inv(A) ; % adjugate, for square invertible matrices
>
> hth
> Jos

I should have thought of this myself. In the very chapter I'm
studying I learned that,

inv(A) = 1/det(A) * adj(A)

(in fact, this is why I'm computing adj(A) in the first place, but
I'm doing it by hand and want to be able to check it with Matlab)

I guess it makes sense that,

adj(A) = det(A) * inv(A)

Thanks.

Greg von Winckel

unread,
Oct 17, 2006, 6:18:07 PM10/17/06
to
That is the case when A is nonsingular. However, adj(A) will always
exist even if inv(A) does not.

-Greg

Roger Stafford

unread,
Oct 18, 2006, 1:55:37 AM10/18/06
to
In article <ef43...@webcrossing.raydaftYaTP>, "Greg von Winckel"
<greg...@mathDEL.unmDEL.edu> wrote:

> That is the case when A is nonsingular. However, adj(A) will always
> exist even if inv(A) does not.
>
> -Greg

---------------------
I believe the 'svd' function can be used to find the adjoint (or
adjugate) of a square matrix A even if it is not invertible. This method
avoids having to tediously compute n^2 different n-1 x n-1 cofactor
determinants.

n = size(A,1);
[u,s,v] = svd(A);
s = diag(s);
ix = toeplitz(ones(n-1,1),[1 zeros(1,n-1)])+repmat((1:n-1)',1,n);
B = v*diag(prod(reshape(s(ix),n-1,n)))*u'/det(v*u'); % B = adj(A)

(To ease the understanding of index ix, I point out that each of the terms
used in the diagonal matrix for obtaining B in the last line is the
product of all but one of the diagonal terms in s.)

Roger Stafford

Roger Stafford

unread,
Oct 18, 2006, 2:26:51 AM10/18/06
to
In article
<ellieandrogerxyzz...@dialup-4.232.57.48.dial1.losangeles1.level3.net>,
ellieandr...@mindspring.com.invalid (Roger Stafford) wrote:

> I believe the 'svd' function can be used to find the adjoint (or
> adjugate) of a square matrix A even if it is not invertible. This method
> avoids having to tediously compute n^2 different n-1 x n-1 cofactor
> determinants.
>
> n = size(A,1);
> [u,s,v] = svd(A);
> s = diag(s);
> ix = toeplitz(ones(n-1,1),[1 zeros(1,n-1)])+repmat((1:n-1)',1,n);
> B = v*diag(prod(reshape(s(ix),n-1,n)))*u'/det(v*u'); % B = adj(A)
>
> (To ease the understanding of index ix, I point out that each of the terms
> used in the diagonal matrix for obtaining B in the last line is the
> product of all but one of the diagonal terms in s.)
>
> Roger Stafford

------------------
I think it is conceptually better to write that last line as:

B = det(u*v')*v*diag(prod(reshape(s(ix),n-1,n)))*u'; % B = adj(A)

though the answer is the same. This way shows its derivation better from

det(A)*inv(A) = det(u*s*v') * v*inv(s)*u'
= det(u*v') * v*(inv(s)*det(s))*u'

as a limiting case as A approaches singularity. After cancellation, the
diagonal terms in inv(s)*det(s) each have all but one of the terms in s,
and a zero-divided-by-zero situation is avoided.

Roger Stafford

Roger Stafford

unread,
Oct 18, 2006, 5:21:28 PM10/18/06
to
In article <ef43...@webcrossing.raydaftYaTP>, "Greg von Winckel"
<greg...@mathDEL.unmDEL.edu> wrote:

------------------
Hello Greg,

You were too quick to accept the correction concerning the factor
(-1)^(j+k) which I made yesterday to your "educational" adj function. It
turns out you need it in case n = size(A,1) is even but not if n is odd.
The OP's case was odd and the factor would then be incorrect, so I jumped
to the erroneous conclusion that it should never be used. Doh! for me
too.

Roger Stafford

Greg von Winckel

unread,
Oct 19, 2006, 11:20:22 AM10/19/06
to
Third time's a charm:

function B=adj(A)

n=size(A,1); d=1:n-1;
B=zeros(n); c=2*mod(size(A,1),2)-1;

AA=[A,A;A,A]';

for j=1:n
for k=1:n

B(j,k)=c^(j+k)*det(AA(j+d,k+d));
end
end

Joe

unread,
Jun 18, 2012, 9:40:07 PM6/18/12
to
It is a one liner!!
adjunct_A=inv(A)*det(A)

Reasoning:
inv(A)=adjunct(A)/det(A)

enjoy.
Joe


"David Scott" <ded...@gmail.com> wrote in message <ef43d...@webcrossing.raydaftYaTP>...

Nasser M. Abbasi

unread,
Jun 18, 2012, 10:28:56 PM6/18/12
to
On 6/18/2012 8:40 PM, Joe wrote:
> It is a one liner!!
> adjunct_A=inv(A)*det(A)
>
> Reasoning:
> inv(A)=adjunct(A)/det(A)
>
> enjoy.
> Joe
>

This above does not work if det(A)=0

-------------------
A=[2 2;
2 2]

inv(A)*det(A)
Warning: Matrix is singular to working precision.

ans =

NaN NaN
NaN NaN
---------------------

However, the Adjunct of A is defined even for singular matix as
this, and it is

2 -2
-2 2

fyi, Mathematica has a Cofactor function that allows
finding the cofactor for each matrix element. Then one
simply transposes the result to obtain the adjunct matrix

----------------------------
<<"Combinatorica`"
mat={{2,2},{2,2}}
cof=Table[Cofactor[mat,{i,j}],{i,2},{j,2}];
adjunct=Transpose[cof]

Out[9]= {{2, -2},
{-2, 2}}
------------------

It can be used on symbolic matrices ofcourse

-------------------

mat ={ {a, b},
{c, d} };

cof = Table[Cofactor[mat,{i,j}],{i,2},{j,2}];
adjunct = Transpose[cof]

Out[18]= {{d, -b},
{-c, a}}

------------------------

There has been some discussion on this sometime ago here I
remember. I think something on Matlab file exchange can do this.
may be OP can google it.

--Nasser

Matt J

unread,
Jun 19, 2012, 4:40:07 AM6/19/12
to
"Nasser M. Abbasi" <n...@12000.org> wrote in message <jroo5a$tr0$1...@speranza.aioe.org>...
>
> This above does not work if det(A)=0
>
> -------------------
> A=[2 2;
> 2 2]
===============


How about this? Too painful for large matrices? I wonder if that can be avoided, and if one would even want the adjunct for large A.


>> c=poly(A); adjunct_A=-polyvalm(c(1:end-1),A)

adjunct_A =

2 -2
-2 2
0 new messages