(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 = | .58+.81i .61+.94i .11+.16i 1+.68i .32+.91i .08+.72i .11+.73i
| .033+.32i .016+.22i .81+.69i .82+.78i .13+.17i .7+.85i .86+.88i
| .18+.18i .62+.68i .86+.95i .71+.63i .44+.19i .6+.5i .65+.32i
| .82+.67i .27+.14i .86+.42i .17+.53i .47+.66i .41+.72i .4+.93i
| .63+.03i .62+.41i .01+.043i .95+.93i .2+.7i .081+.43i .73+.23i
| .16+.81i .25+.11i .21+.98i .04+.95i .34+.75i .89+.07i .62+.83i
| .52+.01i .05+.51i .92+.22i .21+.26i .65+.29i .38+.43i .65+.44i
| .86+.95i .19+.001i .65+.04i .72+.34i .44+.86i .93+.14i .64+.22i
| .72+.26i .99+.1i .31+.3i .004+.28i .69+.42i .38+.31i .13+.058i
| .86+.85i .9+.59i 1+.81i .21+.94i .26+.5i .11+.75i .44+.12i
-----------------------------------------------------------------------
.95+.05i .097+.19i .9+.45i |
.92+.78i .51+.42i .98+.93i |
.34+.91i .24+.044i .02+.19i |
.6+.15i .36+.74i .6+.81i |
.8+.71i .98+.57i .36+.92i |
.7+.18i .69+.41i .74+.71i |
.13+.45i .29+.16i .56+i |
.69+.45i .71+.56i .27+.19i |
.9+.3i .82+.99i .95+.84i |
.81+.57i .13+.31i .52+.61i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .64+.55i .56+.56i |
| .57+.83i .74+.04i |
| .66+.3i .92+.84i |
| .16+.59i .63+.57i |
| .43+.78i .27+.77i |
| .65+.83i .27+.19i |
| .06+.77i .44+.73i |
| .42+.15i .84+.32i |
| .25+.81i .7+.03i |
| .82+.68i .98+.47i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .12+.25i -1-i |
| .28+.25i -.37+.083i |
| .015-.17i -.27+.7i |
| -.078-.27i -.2-.87i |
| -.14-.44i 2.6+1.1i |
| .045+.1i .12-1.5i |
| .23-.002i .56+.85i |
| .28-.33i 1.1+.5i |
| -.27+.44i -.27-.2i |
| .45+.45i -1.1+.06i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 8.08254562088053e-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 = | .49 .97 .49 .27 .55 |
| .46 .0013 .91 .92 .12 |
| .76 .56 .64 .67 .64 |
| .76 .17 .28 .41 .49 |
| .97 .2 .73 .45 .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 = | 7.9 5.5 -17 13 -2.4 |
| 16 11 -31 22 -6.5 |
| -24 -18 50 -38 11 |
| 23 19 -48 36 -11 |
| -24 -18 48 -34 8.9 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 7.105427357601e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 5.32907051820075e-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 = | 7.9 5.5 -17 13 -2.4 |
| 16 11 -31 22 -6.5 |
| -24 -18 50 -38 11 |
| 23 19 -48 36 -11 |
| -24 -18 48 -34 8.9 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|