(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 = | .75+.97i .38+.78i .96+.76i .047+.11i .73+.1i .01+.88i .61+.84i
| .21+.63i .49+.33i .05+.79i .24+.34i .3+.53i .94+.51i .45+.33i
| .16+.45i .85+.77i .45+.88i .67+.53i .2+.48i .77+.91i .63+.77i
| .52+.81i .16+.3i .85+.34i .67+.2i .64+.56i .11+.52i .052+.5i
| .6+.57i .06+.69i .35+.17i .65+.07i .94+.61i .46+.65i .047+.31i
| .57+.59i .06+.73i .15+.81i .72+.8i .7+.86i .37+.92i .57+.55i
| .14+.61i .94+.27i .43+.18i .39+.78i .3+.35i .46+.87i .66+.25i
| .92+.51i .9+.12i .79+.91i .92+.74i .07+.77i .51+.09i .83+.37i
| .96+.49i .44+.68i .48+.51i .09+.33i .65+.49i .51+.28i .4+.54i
| .22+.54i .12+.38i .19+.65i .39+.059i .59+.99i .91+.99i .35+.6i
-----------------------------------------------------------------------
.43+.94i .74+.68i .0048+.046i |
.4+.61i .23+.87i .74+.83i |
.13+.22i .59+.4i .61+.48i |
.11+.11i .2+.68i .1+.88i |
.42+.63i .73+.87i .78+.15i |
.56+.36i .53+.74i .04+.74i |
.5+.24i .76+.32i .22+.38i |
.5+.57i .94+.49i .34+.073i |
.91+.35i .33+.53i .89+.43i |
.42+.16i .94+.5i .022+.18i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .36+.45i .94+.53i |
| .46+.054i .18+.85i |
| .09+.7i .59+.15i |
| .52+.92i .36+.82i |
| .03+.54i .45+.99i |
| .4+.68i .35+.25i |
| .85+.94i .12+.96i |
| .36+.054i .56+.66i |
| .073+.49i .84+.52i |
| .39+.99i .5+.73i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .83-.76i .32+.79i |
| .97+.55i -.65+1.6i |
| -1 .55-.54i |
| -.53+.3i -1.1i |
| .71-.06i .76+.7i |
| -.41-.13i .47-.6i |
| .57+.53i -1.1-1.7i |
| -.97+.63i .21-.86i |
| .55-.18i -.06+1.1i |
| -.2-.51i .6+.17i |
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 = | .61 .36 .9 .24 .32 |
| .099 .24 .67 .78 .71 |
| .17 .012 .81 .49 .12 |
| .23 .97 .089 .67 .25 |
| .42 .2 .64 .53 .084 |
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 = | .31 .38 -3.6 -.97 3.9 |
| .76 -.85 1.5 1.4 -2.3 |
| .76 -.66 2.7 .3 -2.2 |
| -1.5 .54 -.63 -.041 2.4 |
| .69 1.7 -1.8 -.58 -.32 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 4.44089209850063e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 5.13478148889135e-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 = | .31 .38 -3.6 -.97 3.9 |
| .76 -.85 1.5 1.4 -2.3 |
| .76 -.66 2.7 .3 -2.2 |
| -1.5 .54 -.63 -.041 2.4 |
| .69 1.7 -1.8 -.58 -.32 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|