## Determinate if a Matrix has an invers.

6 posts
• Page

**1**of**1**### Determinate if a Matrix has an invers.

3 3 matrix:

Coefs

3 ¯2 4

2 4 ¯4

5 ¯1 1

Is the following expression correct ?

(⌹Coefs) +.× Coefs = Coefs +.× (⌹Coefs)

gives:

0 0 0

0 0 0

0 0 0

All zero's thus my assumption is that this matrix has an invers ?

another matrix :

Coefs

2 ¯1 3 ¯1

4 2 ¯1 ¯3

5 1 1 ¯1

1 1 ¯1 ¯1

The same expression as above gives now :

0 0 8.881784197E¯16 0

0 0 1.000000000E0 0

0 0 5.000000000E¯1 0

0 0 5.000000000E¯1 0

Thus this matrix has no invers ?

Or is there another way with APL to find out if a matrix has an invers ?

Thanks very much to have a look at this.

Henk.

Coefs

3 ¯2 4

2 4 ¯4

5 ¯1 1

Is the following expression correct ?

(⌹Coefs) +.× Coefs = Coefs +.× (⌹Coefs)

gives:

0 0 0

0 0 0

0 0 0

All zero's thus my assumption is that this matrix has an invers ?

another matrix :

Coefs

2 ¯1 3 ¯1

4 2 ¯1 ¯3

5 1 1 ¯1

1 1 ¯1 ¯1

The same expression as above gives now :

0 0 8.881784197E¯16 0

0 0 1.000000000E0 0

0 0 5.000000000E¯1 0

0 0 5.000000000E¯1 0

Thus this matrix has no invers ?

Or is there another way with APL to find out if a matrix has an invers ?

Thanks very much to have a look at this.

Henk.

- hbarkhof
**Posts:**29**Joined:**Mon Apr 09, 2018 8:37 am

### Re: Determinate if a Matrix has an invers.

Henk,

If your matrix has an inverse then ⌹Coefs will return the inverse. If it does not have an inverse (we say it is *singular*) then ⌹Coefs will generate a DOMAIN ERROR. You could write a dfn to test whether a matrix is singular like this:

It gets a bit more complicated if your matrix is very large, or numerically very close to being singular, but for small simple matrices the above method should be fine.

Jay.

If your matrix has an inverse then ⌹Coefs will return the inverse. If it does not have an inverse (we say it is *singular*) then ⌹Coefs will generate a DOMAIN ERROR. You could write a dfn to test whether a matrix is singular like this:

singular←{

11::1 ⍝ DOMAIN ERROR means it's singular

0⊣⌹⍵ ⍝ otherwise it's not

}

It gets a bit more complicated if your matrix is very large, or numerically very close to being singular, but for small simple matrices the above method should be fine.

Jay.

- Jay|Dyalog
**Posts:**22**Joined:**Mon Aug 09, 2010 10:45 am

### Re: Determinate if a Matrix has an invers.

Thanks Jay. Than I have a follow-up question.

How to determine if the matrix gives a non-singular or singular ?

How to determine if the matrix gives a non-singular or singular ?

- hbarkhof
**Posts:**29**Joined:**Mon Apr 09, 2018 8:37 am

### Re: Determinate if a Matrix has an invers.

Type this into your APL session. (I am defining the dfn all on one line, because it's easier to type into the session.)

The result 0 here means that the matrix Coefs is not singular.

Is this what you want?

Jay.

singular←{11::1 ⋄ 0⊣⌹⍵}

singular Coefs

0

The result 0 here means that the matrix Coefs is not singular.

Is this what you want?

Jay.

- Jay|Dyalog
**Posts:**22**Joined:**Mon Aug 09, 2010 10:45 am

### Re: Determinate if a Matrix has an invers.

That is what I am looking for! Great. Many thanks!

- hbarkhof
**Posts:**29**Joined:**Mon Apr 09, 2018 8:37 am

### Re: Determinate if a Matrix has an invers.

In addition to the function that already Jay gave for determining whether a matrix is singular, the following is also relevant: The expression

does not do what you think it does in APL, because the function = has no special status and has scope similar to other functions such as + or × . APL interprets it as follows, fully parenthesized:

an unusual computation. Whereas I think what was intended is:

However, even this last expression would not always give the expected answer, given the vicissitudes of working with floating point numbers. It's better to use:

the maximum absolute difference between the "LHS" and the "RHS", or

the maximum absolute difference between the identity matrix and a matrix times its inverse.

- Code: Select all
`(⌹Coefs) +.× Coefs = Coefs +.× (⌹Coefs)`

does not do what you think it does in APL, because the function = has no special status and has scope similar to other functions such as + or × . APL interprets it as follows, fully parenthesized:

- Code: Select all
`(⌹Coefs) +.× (Coefs = (Coefs +.× (⌹Coefs)))`

an unusual computation. Whereas I think what was intended is:

- Code: Select all
`((⌹Coefs) +.× Coefs) = (Coefs +.× (⌹Coefs))`

However, even this last expression would not always give the expected answer, given the vicissitudes of working with floating point numbers. It's better to use:

- Code: Select all
`⌈/ | , ((⌹Coefs) +.× Coefs) - (Coefs +.× (⌹Coefs))`

the maximum absolute difference between the "LHS" and the "RHS", or

- Code: Select all
`I←{∘.=⍨⍳⍵} ⍝ identity matrix of order ⍵`

⌈/ | , (I ≢Coefs) - Coefs +.× (⌹Coefs)

⌈/ | , (I ≢Coefs) - (⌹Coefs) +.× Coefs

the maximum absolute difference between the identity matrix and a matrix times its inverse.

- Roger|Dyalog
**Posts:**133**Joined:**Thu Jul 28, 2011 10:53 am

6 posts
• Page

**1**of**1**### Who is online

Users browsing this forum: No registered users and 1 guest

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group