(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 = | .62+.67i .02+.95i .096+.33i .03+.85i .47+.073i .63+.06i .85+.33i
| .51+.09i .42+.68i .77+.47i .43+.41i .73+.97i .53+.23i .8+.88i
| .76+.04i .081+.24i .78+.03i .23+.6i .77+.61i .44+.91i .089+.11i
| .13+.96i .35+.6i .23+.34i .21+.4i .3+.49i .028+.096i .31+.9i
| .42+.041i .72+.56i .79+.18i .32+.97i .4+.73i .33+.64i .72+.3i
| .74+.44i .88+.68i .2+.67i .6+.65i .43+.97i .19+.96i .34+.75i
| .27+.062i .97+.22i .36+.86i .15+.16i .2+.26i .88+.49i .55+.62i
| 1+.2i .55+.26i .51+.95i .37+.29i .93+.71i .14+.77i .68+.18i
| .89+.58i .14+.79i .1+.67i .96+.31i .56+.16i .2+.17i .76+.18i
| .52+.44i .11+.55i .76+.12i .67+.21i .9+.05i .93+.31i .1+.78i
-----------------------------------------------------------------------
.053+.47i .68+.98i .63+.68i |
.96+.72i .52+.09i .78+.94i |
.93+.46i .59+.7i .18+.56i |
.81+.17i .75+.13i .84+.16i |
.95+.11i .3+.92i .6+.5i |
.35+.15i .28+.85i .17+.16i |
.04+.86i .13+.79i .82+.75i |
.16+.014i .48+.65i .6+.86i |
.71+.34i .21+.12i .69+.53i |
.38+.28i .25+.88i .17+.3i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .98+.61i .81+.2i |
| .39+.26i .032+.23i |
| .54+.37i .87+.91i |
| .18+.68i .24+.24i |
| .05+.59i .56+.82i |
| .8+.98i .13+.73i |
| .6+.33i .12+.58i |
| .68+.97i .7+.29i |
| .24+.025i .78+.65i |
| .46+.28i .61+.84i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .27+.4i .34-.17i |
| -.059-.12i -.54+.14i |
| -.59-.1i -.056-.14i |
| -.28-.1i .19+.32i |
| .73-.12i -.59+.32i |
| .27-.26i .46-.35i |
| .27-.12i .18+.27i |
| -.4-.51i .53+.65i |
| .52-.04i .5-.45i |
| .07+.82i .029-.37i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 5.1178752665209e-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 = | .57 .63 .21 .45 .073 |
| .42 .56 .29 .67 .73 |
| .56 .7 .71 .45 .67 |
| .84 .82 .99 .39 .14 |
| .18 .82 .026 .77 .91 |
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 = | 4.4 .028 4.8 -4.3 -3.2 |
| 1 -3.9 1.4 -.15 2 |
| -3.4 1.3 -2.9 3.4 .8 |
| -3.4 4.9 -7.4 4.6 1.1 |
| 1.2 -.73 4.2 -3 -1 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 9.99200722162641e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 1.19348975147204e-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 = | 4.4 .028 4.8 -4.3 -3.2 |
| 1 -3.9 1.4 -.15 2 |
| -3.4 1.3 -2.9 3.4 .8 |
| -3.4 4.9 -7.4 4.6 1.1 |
| 1.2 -.73 4.2 -3 -1 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|