(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 = | 2.2e-16 |
| -2.2e-16 |
| 0 |
3 1
o10 : Matrix RR <--- RR
53 53
|
i11 : norm oo
o11 = 2.22044604925031e-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 = | .15+.21i .75+.62i .89+.76i .32+.78i .33+.87i .41+.24i .46+.81i
| .2+.26i .81+.17i .45+.21i .51+.56i .42+.13i .39+.68i .91+.34i
| .92+.11i .42+.58i .41+.36i .05+.59i .28+.13i .52+.99i .22+.3i
| .42+.23i .61+.23i .098+.43i .67+.81i .18+.26i .12+.58i .64+.39i
| .96+.49i .93+.61i .86+.61i .72+.1i .69+.19i .001+.4i .87+.31i
| .9+.06i .8+.77i .65+.67i .49+.6i .54+.31i .13+.5i .02+.89i
| .57+.2i .13+.47i .26+.17i .16+.04i .2+.19i .74+.73i .57+.75i
| .51+.24i .92+.86i .65+.88i .069+.17i .97+.51i .21+.97i .32+.49i
| .06+.77i .78+.12i .79+.54i .54+.99i .88+.85i .38+.25i .63+.32i
| .068+.14i .38+.13i .64+.91i .81+.65i .48+.51i .68+.21i .08+.6i
-----------------------------------------------------------------------
.56+.54i .37+.83i .51+.47i |
.63+.79i .85+.9i .53+.89i |
.61+.01i .1+.81i .53+.47i |
.22+.49i .8+.25i .38+.53i |
.63+.86i .65+.7i .24+.71i |
.52+.06i .76+.29i .91+.33i |
.45+.43i .87+.89i .073+.14i |
.47+.97i .19+.65i .18+.41i |
.25+.86i .61+.45i .73+.6i |
.68+.33i .48+.95i .51+.98i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .34+.19i .06+.51i |
| .54+.35i .59+.53i |
| .73+.29i .16+.48i |
| .9+.3i 1+.5i |
| .79+.62i .34+.4i |
| .39+.77i .85+.32i |
| .088+.36i .78+.96i |
| .63+.09i .5+.88i |
| .05+.76i .14+.53i |
| .99+.46i .61+.24i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .53+2.7i -.73+.11i |
| -2.7+1.7i -.36-.92i |
| -.04-4.1i .69+.2i |
| -1.2-1.3i .79-.55i |
| 1.7+1.3i .06+.61i |
| -2.3+.16i .36-.96i |
| 2.7+.91i -.6+.09i |
| .01+.22i .36+.085i |
| .65-1.6i 1.1+1.1i |
| .94+1.4i -1.1-.23i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.52731344151809e-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 = | .34 .72 .65 .23 .91 |
| .63 .16 .82 .015 .37 |
| .83 .14 .95 .17 .91 |
| .14 .84 .44 .5 .33 |
| .82 .0059 .33 .7 .72 |
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.8 8.3 -10 -4.8 3.7 |
| 4.5 5.1 -7 -2.4 1.8 |
| -5.4 -5.1 8.3 4.2 -3.1 |
| -4.8 -5.1 6.4 4 -1.2 |
| .61 -2.1 1.7 -.41 -.27 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 3.5527136788005e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 6.21724893790088e-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 = | 5.8 8.3 -10 -4.8 3.7 |
| 4.5 5.1 -7 -2.4 1.8 |
| -5.4 -5.1 8.3 4.2 -3.1 |
| -4.8 -5.1 6.4 4 -1.2 |
| .61 -2.1 1.7 -.41 -.27 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|