(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 = | .17+.12i .3+.82i .72+.09i .082+.34i .26+.93i .21+.93i .74+.44i
| .35+.46i .56+.8i .34+.66i .85+.22i .063+.33i .75+.27i .59+.27i
| .17+.93i .15+.91i .66+.92i .84+.74i .35+.71i .68+.79i .08+.8i
| .24+.98i .32+.12i .93+.23i .25+.64i .92+.14i .21+.53i .04+.66i
| .63+.53i .06+i .35+.33i .51+.56i .85+.72i .75+.8i .58+.82i
| .51+.74i .9+.83i .22+.87i .29+.97i .81+.71i .14+.82i .6+.32i
| .73+.7i .97i .15+.41i .29+.12i .98+.01i .46+.62i .41+.47i
| .93+.88i .46+.2i .65+.19i .53+.18i .69+.99i .41+.69i .23+.41i
| .82+.79i .29+.75i .23+.37i .59+.29i .23+.38i .45+.6i .34+.18i
| .62+.28i .04+.68i .86+.22i .36+.99i .18+.18i .21+.53i .5+.22i
-----------------------------------------------------------------------
.24+.084i .51+.72i .51+.25i |
.37+.87i .4+.17i .66+.33i |
.44+.54i .95+.35i .99i |
.62+.26i .34+.24i .59+.09i |
.71+.57i .3+.94i .84+.53i |
.47+.079i .5+.02i .044+.1i |
.35+.83i .78+.31i .96+.22i |
.71+.66i .53+.6i .96+.53i |
.82+.59i .36+.27i .7+.59i |
.17+.21i .33+.73i .74i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .1+.63i .8+.62i |
| .88+.66i .43+.13i |
| .04+.52i .47+.57i |
| .78+.16i .29+.67i |
| .92+.39i .56+.13i |
| .97+.26i .12+.99i |
| .17+.84i .76+.39i |
| .39+.64i .43+.7i |
| .51+.76i .64+.63i |
| .47+.8i .32+.48i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .041+.33i .16-.18i |
| -.23-.79i -.82-.55i |
| .35+.26i .72-.06i |
| .93-1.2i .28+.36i |
| .38-.68i -.028-.14i |
| -.04+.64i .75-1.1i |
| -.52+.43i -.28+.88i |
| .29-.32i -.29+.34i |
| -.86+.46i -.32+.43i |
| .4+i .25+.59i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 8.67111901826274e-16
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 = | .77 .15 .69 .74 .13 |
| .7 .7 .5 .082 .75 |
| .086 .1 .89 .11 .91 |
| .88 .71 .37 .4 .85 |
| .9 .31 .12 .73 .18 |
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 = | -6.5 9.7 3.8 -14 13 |
| 7.5 -8.4 -5.4 15 -14 |
| 2 .094 -.4 .53 -2.3 |
| 5.2 -8.7 -2.8 12 -8.9 |
| -2.8 .99 2.1 -2.3 3.7 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 1.77635683940025e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 8.88178419700125e-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 = | -6.5 9.7 3.8 -14 13 |
| 7.5 -8.4 -5.4 15 -14 |
| 2 .094 -.4 .53 -2.3 |
| 5.2 -8.7 -2.8 12 -8.9 |
| -2.8 .99 2.1 -2.3 3.7 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|