(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 = | .95+.25i .44+.79i .71+.69i .4+.41i .26+.019i .64+.88i .16+.69i
| .37+.33i .1+.91i .84+.69i .58+.17i .02+.47i .62+.14i .18+.59i
| .57+.86i .81+.75i .36+.46i .76+.1i .55+.68i .59+.28i .85+.42i
| .23+.2i .75+.29i .71+.77i .24+.92i .017+.33i .2+.4i .22+.77i
| .73+.22i .79+.51i .29+.85i .16+.74i .1+.81i .82+.08i .15+.56i
| .74+.43i .7+.38i .59+.62i .4+.19i .57+.13i .51+.83i .2+.58i
| .99+.27i .25+.022i .88+.04i .36+.045i .72+.11i .99+.56i .06+.74i
| .72+.1i .16+.11i .46+.89i .48+.67i .39+.13i .88+.44i .75+.72i
| .52+.94i .03+.68i .1+.67i .89+.84i .44+.1i .2+.72i .6+.37i
| .69+.68i .77+.87i .34+.13i .19+.019i .98+.27i .33+.68i .3+.13i
-----------------------------------------------------------------------
.77+.84i .82+.18i .06+.73i |
.15+.55i .34+.85i .89+.52i |
.68+.03i .58+.26i .53+.16i |
.4+.68i .93+.59i .14+.31i |
.47+.87i .46+.11i .84+.76i |
.58+.79i .58+.43i .63+.42i |
.14+.4i .21+.48i .18+.13i |
.52+.02i .28+.032i .77+.02i |
.11+.96i .93+.48i .31+.98i |
.45+.39i .66+.29i .82+.35i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .63+.9i .08+.25i |
| .4+.44i .59+.39i |
| .38+.17i .98+.83i |
| .37+.3i .69+.97i |
| .52+.58i .47+.25i |
| .25+.56i .48+.16i |
| .04+.86i .32+.38i |
| .55+.95i .97+.03i |
| .74+.58i .92+.98i |
| .8+.73i .54+.73i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.36+.17i -2.3+3i |
| .15-.81i -.17+.12i |
| .2+.2i -2.6-2i |
| .05-.85i 2.4+1.8i |
| .47+.67i 2.3-1.8i |
| .41+.24i 2.2-i |
| .06+.42i -2-.65i |
| .1-.04i -2.1+1.4i |
| -.084+.23i 4.1+.24i |
| .11-.053i -.2+.28i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.54237111854025e-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 = | .56 .02 .85 .17 .41 |
| .99 .88 .34 .19 .53 |
| .22 .79 .18 .66 .051 |
| .51 .87 .62 .79 .017 |
| .39 .43 .59 .044 .55 |
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 = | .91 1.4 -.51 .013 -1.9 |
| -2.4 .0045 -1.9 2 1.9 |
| -.79 -.83 -2.5 2.4 1.5 |
| 2.7 -.24 4.4 -2.8 -2.1 |
| 1.9 -.066 4.2 -3.9 .22 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 5.55111512312578e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 7.7715611723761e-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 = | .91 1.4 -.51 .013 -1.9 |
| -2.4 .0045 -1.9 2 1.9 |
| -.79 -.83 -2.5 2.4 1.5 |
| 2.7 -.24 4.4 -2.8 -2.1 |
| 1.9 -.066 4.2 -3.9 .22 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|