(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 = | .4+.31i .46+.44i .64+.11i .25+.69i .35+.41i .91+.89i .04+.74i
| .77+.42i .52+.13i .88+.17i .97+.72i .51+.8i .22+.52i .29+.96i
| .35+.8i .47+.73i .89+.37i .038+.19i .61+.29i .27+.4i .15+.9i
| .79+.81i .32+.19i .14+.12i .87+.95i .97+.02i .1+.58i .7+.54i
| .91+.54i .18+.21i .61+.7i .31+.5i .18+.38i .86+.2i .85+.01i
| .35+.65i .72+.04i .48+.9i .36+.95i .75+.51i .77+.02i .48+.63i
| .18+.11i .055+.4i .92+.29i .51+.72i .95+.48i .99+.86i .17+.87i
| .98+.12i .95+.48i .89+.98i .48+.054i .99+.98i .29+.26i .72+.86i
| .91+.87i .96+.08i .05+.98i .56+.09i .92+.74i .98+.99i .12+.33i
| .97+.08i .15+.74i .65+.25i .55+.34i .58+.72i .24+.31i .04+.9i
-----------------------------------------------------------------------
.47+.16i .51+.02i .77+.79i |
.29+.008i .58+.32i .018+.14i |
.35+.49i .85+.2i .66+.54i |
.02+i .56+.58i .85+.48i |
.64+.62i .51+.9i .32+.76i |
.72+.75i .8+.47i .37+.22i |
.16+.32i .77+.53i .5+.61i |
.92+.14i .49+.63i .53+.47i |
.16+.78i .99+.71i .23+.36i |
.58+.72i .78+.26i .077+.15i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .28+.32i .3+.051i |
| .77+.2i .72+.65i |
| .67+.54i .63+.26i |
| .4+.073i .84i |
| .6+.4i .49+.13i |
| .3+.94i .7+.65i |
| .92+.32i .8+.37i |
| .3+.43i .89+.15i |
| .62+.89i .93+.65i |
| .18+.66i .9+.78i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | 2.5-.3i .36-.091i |
| -3.5-1.9i -1.2-.68i |
| -4.6-3.2i -1-1.2i |
| -1.8-1.9i -.31-.19i |
| -.03+1.3i .16-.21i |
| .019+.072i .14-.34i |
| 3.3-2.1i 1.3-.43i |
| -1.8+6.3i -.17+1.4i |
| 5.5+1.5i 1.7+i |
| -.25+.16i -.42+.38i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 2.59184174787402e-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 = | .74 .88 .82 .3 .95 |
| .5 .88 .21 .27 .54 |
| .35 .11 .91 .35 .46 |
| .42 .9 .53 .32 .72 |
| .73 .11 .31 .52 .21 |
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.3 4.4 1.3 -5.8 -.35 |
| -2.2 8.6 4 -5.3 -2.5 |
| -1.4 7.9 5.4 -6.7 -2.7 |
| -2.2 -6.2 -2.4 8.1 2.9 |
| 4 -16 -8.7 13 4 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 2.22044604925031e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 3.99680288865056e-15
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.3 4.4 1.3 -5.8 -.35 |
| -2.2 8.6 4 -5.3 -2.5 |
| -1.4 7.9 5.4 -6.7 -2.7 |
| -2.2 -6.2 -2.4 8.1 2.9 |
| 4 -16 -8.7 13 4 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|