(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 = | .9+.08i .56+.83i .51+.54i .099+.002i .96+.35i .39+.35i .12+.72i
| .4+.74i .22+.86i .06+.6i .72+.87i .35+.029i .2+.72i .53+.61i
| .89+.51i .17+.68i .64+.84i .072+.5i .88+.5i .97+.77i .68+.62i
| .21+.42i .66+.54i .055+.44i .89+.34i .76+.8i .33+.43i .71+.74i
| .07+.43i .42+.84i .98+.8i .16+.047i .37+.31i .065+.26i .35+.94i
| .72+.5i .43+.88i .75+.81i .95+.68i .33+.58i .19+.83i .14+.84i
| .42+.97i .95+.6i .1+.74i .68+.54i .07+.58i .05+.96i .73+.32i
| .28+.71i .69+.4i .44+.71i .29+.44i .4+.33i .75+.7i .91+.69i
| .28+.31i .31+.53i .97+.69i .59+.93i .98+.07i .73+.73i .66+.13i
| .17+.31i .59+.82i .032+.018i .84+.96i .48+.11i .75+.59i 1+.94i
-----------------------------------------------------------------------
.86+.38i .87+.15i .28+.74i |
.13+.38i .092+.18i .86+.8i |
.97+.75i .96+.67i .83+.58i |
.43+.61i .84+.82i .42+.01i |
.79+.71i .08+.77i .3+.57i |
.64+.88i .96+.14i .33+.025i |
.65+.4i .82+.96i .53+.71i |
.03+.85i .46+.14i .047+.15i |
.56+.54i .93+.32i .7+.85i |
.32+.72i .36+.29i .82+.93i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .35+.25i .78+.12i |
| .53+.52i .81+.87i |
| .33+.95i .6+.2i |
| .64+.81i .59+.86i |
| .67+.48i .3+.84i |
| .01+.83i .38+.39i |
| .85+.93i .86+.73i |
| .23+.15i .35+.84i |
| .85+.56i .53+.24i |
| .55+.32i .44+.041i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .15-.12i 1.6-.3i |
| -.72+.28i -.09+.7i |
| .49-.79i .15+.019i |
| 1.3+.45i .73+.04i |
| -.64+.76i .41+1.2i |
| .94+.74i -.2+.16i |
| .37-1.1i .1-.59i |
| -.71+1.9i -.65+.46i |
| .83-1.2i .01-1.2i |
| -.83-.9i -.6-.33i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 7.30135198854559e-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 = | .072 .39 .64 .97 .85 |
| .99 .88 .019 .23 .23 |
| .23 .39 .041 .45 .73 |
| .77 .98 .93 .42 .68 |
| .96 .39 .77 .66 1 |
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 = | -.26 .71 -.72 -.66 1 |
| .077 .32 .65 .96 -1.3 |
| .091 -.68 -1 .89 .22 |
| 2 1.2 -1.4 -1.3 -.039 |
| -1.2 -1.1 2.2 .44 .36 |
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 = 4.9960036108132e-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 = | -.26 .71 -.72 -.66 1 |
| .077 .32 .65 .96 -1.3 |
| .091 -.68 -1 .89 .22 |
| 2 1.2 -1.4 -1.3 -.039 |
| -1.2 -1.1 2.2 .44 .36 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|