(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 = | .04+.74i .62+.88i .14+.5i .29+.54i .9+.55i .75+.47i .12+.33i
| .45+.78i .57+.08i .86+.77i .42+.025i .24+.83i .24+.26i .59+.22i
| .12+.09i .52+.6i .62+.5i .023+.26i .9+.12i .83+.34i .14+.59i
| .51+.39i .03+.98i .85+.71i .013+.43i .62+.18i .63+.48i .33+.2i
| .77+.55i .07+.93i .07+.57i .7+.74i .08+.65i .28+.41i .03+.71i
| .13+.38i .04+.59i .47+.7i .31+.12i .38+.18i .6+.69i .58+.68i
| .02+i .26+.62i .24+.54i .05+.84i .6+.2i .44+.77i .12+.65i
| .05+.71i .067+.14i .97+.24i .86+.36i .4+.53i .05+.16i .57+i
| .87+.75i .11+.44i .73+.44i .85+.5i .86+.95i .36+.43i .91+.28i
| .61+.94i .21+.73i .08+.49i .08+.51i .89+.16i .04+.85i .4+.32i
-----------------------------------------------------------------------
.68+.64i .82+.26i .58+.77i |
.8+.93i .82+.64i .73+.03i |
.51+.8i .03+.92i .4+.05i |
.98+.54i .19+.52i .66+.36i |
.02+.72i .42+.13i .5+.14i |
.35+.47i .91+.3i .1+.71i |
.13+.9i .54+.77i .78+.86i |
.02+.51i .97+.44i .61+.76i |
.15+.28i .39+.17i .14+.025i |
.27+.99i .73+.55i .44+.23i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .1+.59i .89+.34i |
| .88+.05i .26+.93i |
| .17+.14i .97+.88i |
| .29+.25i .066+.33i |
| .43+.009i .04+.77i |
| .46+.79i .68+.06i |
| .11+.34i .46+.39i |
| .6+.16i .67+.02i |
| .69+.2i .03+.76i |
| .51+.59i .54+.51i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.3-2i -.06+.71i |
| .69-.68i .063+.32i |
| 2-.01i -.14+.07i |
| .38+.63i -.37-.21i |
| -.53+.81i .78-.09i |
| .18-.19i .18+.36i |
| -.94+.21i -.11-.47i |
| -.49-.85i .011-.45i |
| -.19+1.1i .78+.05i |
| -1.4+.61i -.16-.043i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 5.55111512312578e-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 = | .01 .63 .83 .81 .018 |
| .97 .62 .51 .26 .3 |
| .072 .62 .56 .33 .6 |
| .08 .36 .31 .075 .97 |
| .8 .67 .27 .55 .58 |
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 = | .34 1 -2 .83 .078 |
| -2.7 -.81 6.8 -4.4 .84 |
| 1.6 1.7 -2.2 2 -2.1 |
| 1.7 -1.1 -2.9 1.3 1.4 |
| .31 -.25 -1.4 1.8 .24 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 1.25940924355916e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 1.11022302462516e-15
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 = | .34 1 -2 .83 .078 |
| -2.7 -.81 6.8 -4.4 .84 |
| 1.6 1.7 -2.2 2 -2.1 |
| 1.7 -1.1 -2.9 1.3 1.4 |
| .31 -.25 -1.4 1.8 .24 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|