(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 = | -1.1e-16 |
| -7.8e-16 |
| 0 |
3 1
o10 : Matrix RR <--- RR
53 53
|
i11 : norm oo
o11 = 7.7715611723761e-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 = | .17+.29i .55+.81i .5+.28i .65+.03i .21+.63i .85+.42i .44+.36i
| .83+.87i .87+.54i .79+.41i .27+.53i .23+.98i .38+.7i .087+.37i
| .59+.17i .5+.56i .68+.79i .95+.33i .62+.7i .68+.99i .91+.9i
| .54+.58i .4+.22i .9+.51i .21+.73i .041+.13i .63+.82i .38+.21i
| .44+.43i .36+.73i .72+.95i .44+.93i .31+.34i .29+.58i .11+.42i
| .76+.77i 1+.38i .37+.58i .53+.87i .29+.12i .75+.5i .64+.57i
| .82+.37i .78+.89i .55+.99i .8+.3i .41+.25i .92+.18i .89+.33i
| .89+.53i .28+.49i .78+.85i .08+.5i .03+.65i .53+.28i .65+.96i
| .63+.78i .11+.97i .34+.47i .33+.48i .8+.67i .58+.47i .24+.68i
| .89+.23i .27+.46i .13+.46i .38+.5i .19+.82i .02+.51i .9+.06i
-----------------------------------------------------------------------
.14+.82i .55+.02i .02+.8i |
.29+.18i .29+.2i .27+.88i |
.99+.43i .38+.45i .24+.08i |
.17+.36i .05+i .084+.2i |
.12+.094i .4+.51i .91+.87i |
.89+.98i .17+.057i .75+.99i |
.94+.03i .79+.64i .63+.71i |
.26+.089i .87+.23i .54+.68i |
.19+.26i .12+.71i .45+.61i |
.81+.39i .83+.68i .59+.71i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .25+.49i .55+.16i |
| .5+.29i .35+.27i |
| .52+.8i .86+.73i |
| .32+.21i .68+.84i |
| .49+.78i .2+.06i |
| .12+.6i .76+.63i |
| .28+.6i .76+.77i |
| .76+.05i .93+.57i |
| .47+i .16+.75i |
| .06+.57i .69+.36i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | 2.4+.77i 1.6-i |
| -2-1.9i -1.6+1.2i |
| 2.6+.74i 1.4-1.8i |
| -.75+2.7i 1.2+.59i |
| -.45+2.4i 1.3+.79i |
| -1.2-1.7i -1+.82i |
| -1.3-.35i -.15+.96i |
| 1.6-.69i -.05-1.5i |
| -.5+.62i .59+.73i |
| .36-1.3i -1.5-.35i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 2.00148302124336e-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 = | .51 .65 .22 .12 .067 |
| .57 .15 .97 .22 .75 |
| .41 .23 .77 .65 .65 |
| .81 .9 .37 .023 .081 |
| .43 .39 .43 .21 .019 |
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 = | -40 -8.8 11 29 -5.1 |
| 27 5.7 -7.2 -19 2.6 |
| 20 5.6 -6.8 -16 5.6 |
| -11 -3.9 4.8 7.3 -.73 |
| 2.1 .78 .55 -.18 -3.6 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 3.5527136788005e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 7.105427357601e-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 = | -40 -8.8 11 29 -5.1 |
| 27 5.7 -7.2 -19 2.6 |
| 20 5.6 -6.8 -16 5.6 |
| -11 -3.9 4.8 7.3 -.73 |
| 2.1 .78 .55 -.18 -3.6 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|