(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 = | .082+.4i .68+.81i .75+.36i .29+.45i .79+.53i .37+.58i .82+.92i
| .7+.32i .55+.97i .99+.81i .22+.27i .72+.6i .14+.39i .3+.61i
| .45+.3i .27+.95i .91+.26i .9+.03i .63+.34i .27+.97i .73+.93i
| .68+.8i .69+.34i .4+.55i .86+.1i .59+.52i .91+.08i .39+.78i
| .7+.78i .027+.43i .92+.76i .68+.56i .39+.79i .43+.97i .25+.97i
| .3+.52i .35+.17i .22+.41i .5+.59i .83+.19i .53+.38i .99+.89i
| .84+.2i .2+.11i .91+.24i .93+.56i .2+.26i .47+.31i .75+.64i
| .81+.96i .18+.74i .47+.73i .55+.67i .76+.4i .4+.36i .76+.66i
| .18+.48i .58+.43i .35+.36i .43+.36i .18+.39i .45+.77i .82+.61i
| .6+.28i .8+i .62+.29i .67+.96i .3+.099i .51+.06i .12+.53i
-----------------------------------------------------------------------
.087+.17i .99+.21i .89+.58i |
.0066+.021i .93+.64i .79+.23i |
.18+.92i .8+.98i .11+.43i |
.88+.41i .44+.98i .02+.29i |
.38+.13i .25+.14i .56+.51i |
.43+.082i .34+.42i .72+.29i |
.3+.77i .62+.09i .8+.29i |
.04+.55i .12+.49i .37+.73i |
.69+.21i .45+.26i .21+.17i |
.94+.2i .1+.7i .8+.24i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .76+.44i .74+.71i |
| .95+.8i .49+.3i |
| .91+.21i .66+.5i |
| 1+i .83+.48i |
| .72+.86i .2+.2i |
| .07+.54i .93+.32i |
| .95+.04i .26+.96i |
| .37+.15i .54+.62i |
| .64+.48i .61+.42i |
| .68+.66i .51+.91i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.56-1.4i -.24-.22i |
| .049+.38i .18+.19i |
| 2.7+.84i -.35+.27i |
| -.93+.12i .48-.099i |
| -1-.25i .9-.57i |
| -.29+i -.76-.03i |
| .82-.29i .25+.52i |
| .24+.1i .53-.06i |
| -.24-.85i .19-.23i |
| -.24+.31i .18+.08i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 7.55033286377907e-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 = | .79 .74 .48 .25 .47 |
| .88 .17 .58 .5 .8 |
| .023 .9 .95 .86 .28 |
| .69 .81 .83 .27 .46 |
| .14 .78 .16 .17 .16 |
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 = | 5.3 -1.4 .63 -2.1 -3.2 |
| -.051 -.27 -.16 .12 1.4 |
| -1.7 -.24 .045 2.5 -.97 |
| 4.2 -.51 1.9 -3.8 -2 |
| -7.1 3.4 -1.9 2.9 5.1 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 8.88178419700125e-16
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 = | 5.3 -1.4 .63 -2.1 -3.2 |
| -.051 -.27 -.16 .12 1.4 |
| -1.7 -.24 .045 2.5 -.97 |
| 4.2 -.51 1.9 -3.8 -2 |
| -7.1 3.4 -1.9 2.9 5.1 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|