(Disambiguation: for division of matrices, which can also be thought of as solving a system of linear equations, see instead Matrix // Matrix. For lifting a map between modules to a map between their free resolutions, see extend.)
There are several restrictions. The first is that there are only a limited number of rings for which this function is implemented. Second, over
RR or
CC, the matrix
A must be a square non-singular matrix. Third, if
A and
b are mutable matrices over
RR or
CC, they must be dense matrices.
i1 : kk = ZZ/101;
|
i2 : A = matrix"1,2,3,4;1,3,6,10;19,7,11,13" ** kk
o2 = | 1 2 3 4 |
| 1 3 6 10 |
| 19 7 11 13 |
3 4
o2 : Matrix kk <--- kk
|
i3 : b = matrix"1;1;1" ** kk
o3 = | 1 |
| 1 |
| 1 |
3 1
o3 : Matrix kk <--- kk
|
i4 : x = solve(A,b)
o4 = | 2 |
| -1 |
| 34 |
| 0 |
4 1
o4 : Matrix kk <--- kk
|
i5 : A*x-b
o5 = 0
3 1
o5 : Matrix kk <--- kk
|
Over
RR or
CC, the matrix
A must be a non-singular square matrix.
i6 : printingPrecision = 2;
|
i7 : A = matrix "1,2,3;1,3,6;19,7,11" ** RR
o7 = | 1 2 3 |
| 1 3 6 |
| 19 7 11 |
3 3
o7 : Matrix RR <--- RR
53 53
|
i8 : b = matrix "1;1;1" ** RR
o8 = | 1 |
| 1 |
| 1 |
3 1
o8 : Matrix RR <--- RR
53 53
|
i9 : x = solve(A,b)
o9 = | -.15 |
| 1.1 |
| -.38 |
3 1
o9 : Matrix RR <--- RR
53 53
|
i10 : A*x-b
o10 = | 2.2e-16 |
| -2.2e-16 |
| 0 |
3 1
o10 : Matrix RR <--- RR
53 53
|
i11 : norm oo
o11 = 2.22044604925031e-16
o11 : RR (of precision 53)
|
For large dense matrices over
RR or
CC, this function calls the lapack routines.
i12 : n = 10;
|
i13 : A = random(CC^n,CC^n)
o13 = | .98+.05i .99+.83i .94+.95i .58+.82i .49+.89i .21+.89i .25+.29i
| .74+.88i .4+.37i .15+.11i .95+.67i .56+.31i .43+.75i .49+.036i
| .67+.94i .12+.57i .48+.098i .063+.34i .04+.89i .9+.97i .67+.91i
| .52+.38i .69+.94i .71+.95i .58+.98i .53+.24i .68+.32i .96+.47i
| .19+.095i .77+.16i .08+.82i .1+.78i .58+.39i .93+.43i .77+.6i
| .78+.06i .41+.77i .6+.64i .09+.94i .18+.35i .49+.43i .36+.27i
| .19+.75i .48+.16i .42+.08i .43+.082i .24+.95i .3+.37i .73+.19i
| .94+.36i .59+.1i .33+.53i .28+.22i .53+.91i .95+.95i .52+.73i
| .085+.25i .51+.57i .31+.86i .95+.57i .84+.94i .51+.87i .057+.092i
| .012+.22i .02+.51i .78+.93i .84+.84i .46+.053i .41+.53i .35+.063i
-----------------------------------------------------------------------
.98+.9i .68+.66i .62+.84i |
.92+.82i .49+.85i .58+.76i |
.07+.82i .49+.83i .92+.86i |
.098+.46i .44+.71i .66+.87i |
.69+.86i .79+.12i .62+.54i |
.64+.15i .46+.19i .055+.17i |
.11+.33i .08+.35i .66+.94i |
.14+.14i .99+.33i .058+.062i |
.58+.44i .11+.63i .97+.72i |
.66+.71i .97+.67i .83+.59i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .53+.76i .74+.38i |
| .64+.16i .49+.51i |
| .74+.69i .42+.55i |
| .08+.78i .6+.84i |
| .057+.49i .07+.83i |
| 1+.57i .14+.12i |
| .099+.15i .11+.024i |
| .21+.75i .26+.25i |
| .95+.83i .1+.96i |
| .53+.2i .23+.16i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.78+.15i .43+.72i |
| .3-.18i -.31+.14i |
| 1+.23i .38-.45i |
| -.85+.16i .8+.95i |
| -.83-.43i -.32+.21i |
| 3.1-.13i -.31-.058i |
| -.71+2.3i 1.3-.84i |
| .75-.23i .57-.69i |
| -.71-1.8i -1.1-.73i |
| -1.1+.06i -.21+.81i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.99840144432528e-15
o16 : RR (of precision 53)
|
This may be used to invert a matrix over
ZZ/p,
RR or
QQ.
i17 : A = random(RR^5, RR^5)
o17 = | .42 .97 .27 .19 .41 |
| .92 .98 .65 .19 1 |
| .77 .31 .048 .84 .38 |
| .43 .96 .88 .23 .088 |
| .45 .87 .78 .55 .61 |
5 5
o17 : Matrix RR <--- RR
53 53
|
i18 : I = id_(target A)
o18 = | 1 0 0 0 0 |
| 0 1 0 0 0 |
| 0 0 1 0 0 |
| 0 0 0 1 0 |
| 0 0 0 0 1 |
5 5
o18 : Matrix RR <--- RR
53 53
|
i19 : A' = solve(A,I)
o19 = | -.71 1.1 .94 1.2 -2 |
| 1.8 -.58 -.2 .025 -.14 |
| -1.6 .32 -.36 .81 .67 |
| .12 -1 .67 -.42 1.3 |
| -.071 .57 -.56 -1.5 1.3 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 3.33066907387547e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 9.99200722162641e-16
o21 : RR (of precision 53)
|
Another method, which isn't generally as fast, and isn't as stable over
RR or
CC, is to lift the matrix
b along the matrix
A (see
Matrix // Matrix).
i22 : A'' = I // A
o22 = | -.71 1.1 .94 1.2 -2 |
| 1.8 -.58 -.2 .025 -.14 |
| -1.6 .32 -.36 .81 .67 |
| .12 -1 .67 -.42 1.3 |
| -.071 .57 -.56 -1.5 1.3 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|