(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 = | .61+.78i .13+.94i .24+.98i .63+.42i .23+.87i .16+.92i .59+.08i
| .57+.73i .53+.96i .81+.83i .57+.29i .48+.041i .33+.33i .61+.59i
| .83+.39i .59+.93i .55+.02i .6+.6i .46+.47i .94+.12i .94+.67i
| .31+.94i .68+.63i .66+.21i .19+.41i .36+.76i .05+.86i .9+.85i
| .62+.05i .01+.86i .4+.25i .74+.62i .63+.18i .99+.96i .87+.29i
| .56+.94i .78+.22i .073+.14i .76+.27i .16+.55i .58+.73i .63+.33i
| .26+.27i .037+.37i .53+.01i .98+.83i .97+.64i .92+.54i .99+.45i
| .46+.6i .04+.56i .45+.37i .89+.5i .13+.26i .55+.28i .86+.81i
| .44+.8i .24+.76i .65+.22i .21+.8i .089+.45i .38+.75i .41+.1i
| .32+.8i .62+.34i .34+.021i .74+.13i .57+.94i .58+.69i .05+.98i
-----------------------------------------------------------------------
.46+.29i .97+.24i .037+.5i |
.93+.2i .49+.55i .053+.055i |
.05+.96i .69+.29i .08+.58i |
.6+.61i .25+.66i .45+.98i |
.12+.64i .31+.38i .68+.81i |
.34+.49i .006+.27i .42+.96i |
.12+.14i .23+.31i .97+.98i |
.9+.35i .31+.04i .24+.14i |
.58+.9i .41+.026i .64+.05i |
.27+.75i .33+.73i .31+.62i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .64+.38i .84+.36i |
| .42+.31i .47+.78i |
| .041+.41i .34+.36i |
| .78+.53i .94+.97i |
| .59+.94i .41+.84i |
| .41+.23i .35+i |
| .66+.83i .17+.59i |
| .76+.83i .84+.32i |
| .59+.82i .48+.36i |
| .79+.64i .57+.81i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.005-.3i .75+1.3i |
| -.67-1.3i 1.6-.74i |
| -.3+1.2i -1.1-.56i |
| .03+.77i .15+.095i |
| -.2-.17i -1.2-.51i |
| .094-.044i -1.1-.64i |
| -.58-.17i .36-2i |
| 1.1+.63i -.75+.9i |
| .47+.11i .54+.53i |
| .71-.61i 2.3+1.3i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.80731214395321e-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 = | .69 1 .54 .15 .12 |
| .3 .82 .44 .079 .83 |
| .71 .25 .35 .27 .29 |
| .56 .26 .2 .33 .31 |
| .33 .072 .84 .19 .44 |
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 = | -.38 .11 4.5 -2.9 -1 |
| 1 .21 -1.9 1.2 -.25 |
| .55 -.45 -.68 -.42 1.5 |
| .68 -1.3 -6.9 7.9 1.3 |
| -1.2 1.3 1.2 -.62 -.29 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 8.88178419700125e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 9.99200722162641e-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 = | -.38 .11 4.5 -2.9 -1 |
| 1 .21 -1.9 1.2 -.25 |
| .55 -.45 -.68 -.42 1.5 |
| .68 -1.3 -6.9 7.9 1.3 |
| -1.2 1.3 1.2 -.62 -.29 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|