(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 = | .65+.92i .69+.07i .52+.74i .35+.28i .22+.98i .49+.84i .15+.45i
| .48+.9i .14+.5i .91+.34i .64+.26i .84+.57i .61+.26i .2+.15i
| .25+.82i .19+.7i .72+.93i .71+.71i .22+.083i .62+.71i .24+.63i
| .51+.59i .84+.49i .17+.57i .59+.09i .21+.67i .33+.21i .89+.07i
| .2+.28i .85+.95i .18+.82i .48+.94i .32+.43i .75+.94i .081+.17i
| .67+.82i .44+.034i .007+.083i .88+.58i .79+.48i .71+.16i .43+.49i
| .44+.82i .71+.49i .99+.52i .26+.8i .81+.73i .45+.58i .89+.61i
| .64+.49i .56+.24i .66+.6i .19+.53i .3+.7i .65+.06i .74+.9i
| .85+.94i .19+.33i .61+.17i .45+.79i .053+.089i 1+.27i .1+.13i
| .001+.3i .4+.053i .94+.42i .64+.13i .5+.89i .83+.69i 1+.99i
-----------------------------------------------------------------------
.57+.83i .17+.76i .21+.04i |
.2+.2i .24+.69i .59+.67i |
.72+.06i .83+.64i .84+.26i |
.69+.47i .53+.82i .71+.85i |
.35+.057i .51+.71i .56+.63i |
.95+.92i .51+.49i .68+.03i |
1+.1i .97+.95i .49+.17i |
.3+.67i .76+i .43+.92i |
.48+.72i .43+.83i .05+.52i |
.32+.96i .67+.05i .068+.12i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .91+.61i .28+.45i |
| .2+.38i .66+.9i |
| .41+.29i .93+i |
| .22+.4i .031+.1i |
| .07+.61i .46+.78i |
| .94+.76i .42+.88i |
| .4+.22i .66+.74i |
| .17+.68i .76+.06i |
| .74+.68i .06+.85i |
| .56+.97i .93+.73i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .43+.021i .82-.9i |
| .61+.07i 1.2-.92i |
| .71-.37i .47-.85i |
| .056-.33i -.79+.17i |
| .16+.49i 1+.78i |
| -.43+.17i -.6+.49i |
| -.46-.16i -.9-1.3i |
| 1.1-.7i .58-.2i |
| -.62+i .22+2.9i |
| -.23-.32i -.57-1.2i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.02357505330418e-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 1 .017 .43 .51 |
| .79 .96 .48 .3 .66 |
| .17 .53 .23 .71 .32 |
| .1 .56 .42 .55 .26 |
| .36 .66 .78 .32 .45 |
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 = | -8.6 13 -5 15 -14 |
| 1.3 .12 -4.4 5.6 -1.8 |
| -2.5 2.5 -2 4.3 -2 |
| -3.4 4 .38 4.8 -5.1 |
| 12 -18 14 -31 24 |
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 = 4.44089209850063e-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 = | -8.6 13 -5 15 -14 |
| 1.3 .12 -4.4 5.6 -1.8 |
| -2.5 2.5 -2 4.3 -2 |
| -3.4 4 .38 4.8 -5.1 |
| 12 -18 14 -31 24 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|