(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 = | 0 |
| -3.3e-16 |
| -8.9e-16 |
3 1
o10 : Matrix RR <--- RR
53 53
|
i11 : norm oo
o11 = 8.88178419700125e-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 = | .18+.32i .87+.15i .63+.14i .73+.68i .59+.18i .27+.84i .53+.89i
| .67+.43i .12+.89i .75+.05i .48+.51i .82+.95i .39+.52i .56+.41i
| .43+.18i .49+.15i .051+.081i .64+.21i .39+.6i .33+.37i .78+.29i
| .76+.01i .7+.55i .62+.1i .088+.48i .42+.2i .56+.07i .89+.26i
| .94+.88i .74+.51i .67+.62i .91+.55i .27+.63i .42+.67i .007+.2i
| .5+.11i .85+.04i .61+.98i .86+.52i .5+.68i 1+.61i .48+.12i
| .35+.93i .97+.56i .85+.62i .23+.78i .36+.12i .19+.95i .56+.05i
| .99+.47i .33+.16i .46+.64i .42+.95i .49+.14i .74+.78i .3+.68i
| .97+.04i .91+.94i .78+.19i .13+.075i .87+.74i .45+.44i .82+.17i
| .42+.61i .13+.19i .05+.8i .87+.23i .52+.39i .48+.51i .87+.94i
-----------------------------------------------------------------------
.45+.21i .15+.77i .75+.52i |
.11+.6i .34+.41i .4+.41i |
.32+.47i .44+.93i .18+.35i |
.2+.54i .37+.71i .46+.52i |
1+.32i .008+.28i .3+.13i |
.25+.54i .26+.43i .32+.2i |
.77+.19i .57+.99i .72+.33i |
.095+.18i .96+.88i .61+.7i |
.14+.95i .24+.28i .046+.11i |
.84+.74i .19+.67i .73+.25i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .9+.48i .18+.9i |
| .26+.27i .45+.99i |
| .04+.54i .55+.4i |
| .052+.026i .46+.86i |
| .41+.22i .96+.53i |
| .68+.73i .91+.74i |
| .97+.53i .37+.45i |
| .88+.24i .64+.95i |
| .56+.52i .25+.55i |
| .89+.24i .1+.8i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.21-.097i 1.7+.56i |
| .54i -1.2+.37i |
| .54-.2i .62-.26i |
| -.4+.28i 2.2+.3i |
| .39+.32i -.04+1.6i |
| .08-.69i -1.3-1.1i |
| -.26-.48i .19+2.5i |
| .23-.53i -1.1-.94i |
| .44+.11i -1.5-.77i |
| .097+.45i .58-1.3i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.27675647831893e-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 = | .31 .47 .12 .23 .038 |
| .16 .97 .83 .93 .59 |
| .067 .84 .76 .74 .23 |
| .084 .51 .14 .88 .36 |
| .83 .37 .85 .29 .3 |
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 = | 1 -.72 -.54 .64 .94 |
| 2.4 1.3 -.46 -1.3 -.97 |
| -1.6 -.43 1.5 -.56 .6 |
| -1.2 -2.1 1.5 2.2 .47 |
| -.16 3.7 -3.5 -.79 -.26 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 4.16333634234434e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 3.46944695195361e-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 = | 1 -.72 -.54 .64 .94 |
| 2.4 1.3 -.46 -1.3 -.97 |
| -1.6 -.43 1.5 -.56 .6 |
| -1.2 -2.1 1.5 2.2 .47 |
| -.16 3.7 -3.5 -.79 -.26 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|