(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 = | .54+.16i .51+.72i .89+.22i .42+.76i .81+.28i .26+.48i .81+.38i
| .62+.67i .83+.04i .59+.49i .16+.46i .85+.19i .51+.76i .41+.41i
| .73+.77i .018+.41i .61+.97i .58+.66i .093+.15i .01+.13i .62+.45i
| .41+.82i .66+.97i .17+.63i .029+.26i .009+.46i .06+.85i .23+.6i
| .42+.86i .59+.68i .1+i .12+.8i .45+.37i .16+.082i .76+.66i
| .74+.77i .24+.047i .75+.8i .15+.78i .06+.96i .94+.27i .84+.64i
| .94+.99i .79+.18i .42+.11i .11+.12i .26+.008i .12+.19i .81+.73i
| .35+.71i .99+.43i .13+.85i .45+.96i .47+.4i .12+.53i .21+.85i
| .58+.64i .05+.66i .07+.64i .67+.19i .59+.26i .14+.041i .54
| .29+.76i .19+.47i .71+.79i .35+.57i .11+.13i .11+.21i .12+.86i
-----------------------------------------------------------------------
.24+.22i .27+.28i .1+.6i |
.16+.26i .28+.34i .34+i |
.81 .41+.4i .66+.24i |
.89+.23i .43+.72i .51+.13i |
.74+.87i .56+.05i .28+.87i |
.87+.14i .62+.86i .33+.13i |
.78+.46i .9+.13i .55+.48i |
.66+.64i .85+.29i .24+.69i |
.01+.27i .2+.093i .22+.61i |
.39+.69i .17+.81i .095+.47i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .052+.35i .9+.83i |
| .15+.34i .53+.73i |
| .46+.082i .5+.42i |
| .2+.57i .13+.31i |
| .65+.91i .19+.34i |
| .08+.94i .023+.49i |
| .88+.95i .52+.44i |
| .92+.71i .6+.93i |
| .19+.5i .77+.63i |
| .45+.75i .67+.34i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | 1.4+.04i .083+.19i |
| -.12-.003i -.62+.9i |
| -.36+.26i -.41-.72i |
| .43-.19i .6+.3i |
| .04+.63i 1.6+1.4i |
| .2+.16i -.82-1.5i |
| -1+.01i 1.3+.51i |
| 1.6-.08i -.14-1.4i |
| .019+.31i .78-1.1i |
| -1.4-.46i -.98+1.6i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.08246744900953e-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 = | .028 .46 .55 .59 .93 |
| .89 .8 .61 .67 .44 |
| .18 .52 .91 .61 .9 |
| .29 .84 1 .15 .99 |
| .27 .017 .97 .85 .15 |
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 = | -21 1.6 36 -12 -11 |
| 25 -.39 -44 15 12 |
| .26 -.58 -2.1 1.7 1.5 |
| 8.9 .083 -14 3.6 4.3 |
| -16 .43 31 -10 -9.2 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 8.88178419700125e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 1.06581410364015e-14
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 = | -21 1.6 36 -12 -11 |
| 25 -.39 -44 15 12 |
| .26 -.58 -2.1 1.7 1.5 |
| 8.9 .083 -14 3.6 4.3 |
| -16 .43 31 -10 -9.2 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|