(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 = | .37+.1i .86+.93i .74+.08i .33+.29i .64+.85i .49+.3i .57+.25i
| .21+.018i .79+.62i .35+.23i .51+.57i .93+.92i .77+.77i .87+.8i
| .21+.96i .63+.99i .48+.57i .7+.3i .57+.96i .57+.77i .78+.34i
| .98+.45i .04+.39i .08+.84i .096+.44i .71+.24i .82+.07i .76+.47i
| .37+.28i .81+.16i .2+.56i .65+.37i .87+i .79+.3i .02+.98i
| .84+.05i .97+.26i .91+.47i .41+.52i .44+.85i .34+.94i .24+.022i
| .97+.14i .47+.62i .15+.72i .12+.43i .24+.52i .27+.38i .44+.65i
| .43+.54i .49+.57i .97+.01i .98+.46i .48+.69i .27+.52i .96+.04i
| .16+.97i .72+.46i .36+.74i .89+.8i .94+.63i .33+.47i .08+.67i
| .026+.24i .56+.05i .027+.36i .46+.77i .37+.27i .9+.64i .39+.42i
-----------------------------------------------------------------------
.51+.4i .95+.62i .37+.51i |
.83+.74i .06+.97i .73+.29i |
.88+.45i .67+.72i .18+.043i |
.35+.69i .63+.65i .93+.99i |
.85+.88i .68+.47i .76+.13i |
.82+.92i .51+.96i .92+.93i |
.65+.81i .58+.27i .51+.21i |
.021+.24i .41+.95i .47+.58i |
.1+.55i .7+.56i .43+.1i |
.09+.093i .84+.8i .68+.59i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .13+.001i .04+.65i |
| .8+.86i .82+.5i |
| .97+.85i .36+.028i |
| .18+.16i .097+.18i |
| .8+.73i .81+.57i |
| .56+.39i .97+.08i |
| .059+.22i .36+.41i |
| .42+.42i .93+.3i |
| .01+.78i .68+.29i |
| .11+.7i .32+.94i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.17-.6i -.058-.34i |
| .98+.24i .7+1.5i |
| .34-.76i .32-.39i |
| -.34+1.8i -.69+.33i |
| -.61-.35i -.12-1.1i |
| .45+.009i -.51-.13i |
| .26-.36i 1.2+.05i |
| -.24+.58i -.93-.42i |
| -.69-.62i .015-.26i |
| 1+.53i .67+.98i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 9.99200722162641e-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 = | .22 .81 .0058 .86 .65 |
| .81 .55 .19 .37 .33 |
| .31 .49 .24 .68 .12 |
| .45 .89 .33 .057 .6 |
| .32 .71 .64 .12 .39 |
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 = | -.37 1.8 -.46 -.43 -.13 |
| -2.1 -2.4 4.2 5 -3.4 |
| .5 .55 -1.3 -2.7 3.3 |
| .98 .41 .015 -1.8 .81 |
| 3 1.9 -5.1 -3.7 3.3 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 3.33066907387547e-16
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 = | -.37 1.8 -.46 -.43 -.13 |
| -2.1 -2.4 4.2 5 -3.4 |
| .5 .55 -1.3 -2.7 3.3 |
| .98 .41 .015 -1.8 .81 |
| 3 1.9 -5.1 -3.7 3.3 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|