(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 = | .12+.55i .54+.32i .08+.94i .22+.75i .8+.29i .79+.69i .95+.36i
| .36+.65i .62+.19i .99+.51i .03+.8i .69+.51i .23+.79i 1+.69i
| .99+.24i .87+.86i .38+.13i .7+.28i .15+.92i .53+.85i .38+.86i
| .14+.78i .39+.6i .32+.47i .98 .51+.2i .09+.64i .04+.84i
| .92+.34i .53+.95i .78+.55i .32+.26i .17+.28i .22+.63i .83+.98i
| .021+.44i .49+.95i .5+.47i .49+.27i .66+.85i .19+.14i .46+.81i
| .88+.94i .35+.006i .46+.37i .58+.82i .2+.6i .51+.18i .25+.74i
| .56+.54i .98+.85i .86+.55i .15+.85i .3+.33i .23+.83i .6+.11i
| .26+.66i .88+.12i .11+.93i .55+.13i .52+.67i .61+.21i .92+.88i
| .86+.51i .35+.53i .024+.14i .57+.78i .075+.097i .48+.49i .48+.48i
-----------------------------------------------------------------------
.06+.75i .2+.72i .024+.32i |
.47+.088i .75+.51i .75+.15i |
.9+.85i .54+.96i .16+.37i |
.51+.01i .17+.26i .33+.69i |
.76+.16i .21+.8i .17+.44i |
.016+.15i .27+.29i .35+.074i |
.49+.66i .45+.75i .34+.23i |
.23+.17i .45+.36i .15+.96i |
.34+.87i .65+.83i .2+.26i |
.25+.26i .5+.46i .39+.26i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .75+.23i .94+.57i |
| .68+.26i .63+.73i |
| .54+.68i .92+.03i |
| .67+.16i .14+.54i |
| .64+.27i .87+.62i |
| .94+.36i .33+.49i |
| .59+.89i .15+.71i |
| .17+.36i .85+.66i |
| .92+.43i .72+.56i |
| .69+.58i .29+.52i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .025-.062i -.09+.8i |
| -.055-.19i -.39+.018i |
| -.54-.03i .88+.2i |
| .48-.22i .2+.15i |
| .33-.31i -.12+.28i |
| -.3+.43i .37-.39i |
| .76+.12i .65-.44i |
| .42-.012i -.51-1.1i |
| -.52+.04i .12+.47i |
| .68-.03i -.16-.56i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 6.75322301446426e-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 = | .24 .071 .5 .65 .55 |
| .68 .17 .23 .18 .8 |
| .39 1 .16 .35 .87 |
| .67 .74 .39 .42 .94 |
| .73 .068 .51 .75 .93 |
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 -2.8 -2.3 3.9 3 |
| -.84 -1.7 -.27 2.2 .011 |
| 3.8 1.2 -3.1 3.9 -4.3 |
| -2.4 -3.4 1 -.74 4.1 |
| 3 4.4 2.7 -4.7 -2.2 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 1.33226762955019e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 8.88178419700125e-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 = | -4 -2.8 -2.3 3.9 3 |
| -.84 -1.7 -.27 2.2 .011 |
| 3.8 1.2 -3.1 3.9 -4.3 |
| -2.4 -3.4 1 -.74 4.1 |
| 3 4.4 2.7 -4.7 -2.2 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|