(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 = | .61+.15i .17+.26i .57+.11i .84+.98i .12+.99i .63+.47i .32+.95i
| .77+.56i .75+.1i .27+.79i .17+.87i .54+.55i .34+.014i .27+.12i
| .084+.45i .65+.91i .19+.21i .84+.51i .4+.17i .04+.69i .37+.2i
| .004+.45i .05+.13i .015+.052i .49+.77i .13+.35i .18+.3i .34+.81i
| .27+.3i .77+.09i .84+.46i .84+.85i .82+.01i .38+.21i .11+.73i
| .77+.77i .75+.51i .86+.44i .97+.32i .97+.57i .92+.16i .76+.53i
| .05+.86i .1+.6i .81+.1i .031+.35i .82+.13i .75+.3i .79+.18i
| .72+.11i .77+i .92+.79i .8+.79i .58+.85i .94+.61i .38+.7i
| .066+.29i .94+.44i .3+.6i .53+.35i .61+.23i .45+.26i .81+.8i
| .27+.73i .76+.27i .44+.44i .84+.95i .21+.87i .31+.6i .51+.42i
-----------------------------------------------------------------------
.7+.84i .37+.9i .84+.44i |
.83+.43i .34+.22i .49+.96i |
.41+.49i .35+.23i .91+.28i |
.72+.92i .32+.35i .27+.64i |
.22+.8i .26+i .28+.33i |
.78+.32i .62+.1i .25+.81i |
.95+.12i .95+.54i .95+.9i |
.49+.44i .74+.65i .96+.07i |
.49+.58i .17+.4i .99+.01i |
.33+.089i .9+.53i .6+.81i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .37+.85i .84+.54i |
| .72+.78i .18+.85i |
| .74+.66i .078+.44i |
| .01+.85i .36+.065i |
| .44+.95i .71+.58i |
| .62+.39i .8+.18i |
| .69+.55i .96+.05i |
| .086+.18i .17+.88i |
| .24+.099i .26+.83i |
| .81+.45i .24+.75i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.23-1.9i .24-1.4i |
| .43-.21i -.029+.39i |
| .63-.08i 1.2+.86i |
| .68+1.7i -.45+.65i |
| -.18-1.2i .81-i |
| -1.8+1.9i -1.5+.17i |
| -2-.29i -.72-.76i |
| .98+.12i .75 |
| .49-.71i -.071-.11i |
| 1+.31i .23+.88i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 9.15513359704447e-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 = | .26 .83 .93 .1 .84 |
| .89 .69 .99 .88 .28 |
| .64 .79 .48 .35 .82 |
| .61 .9 .41 .4 .24 |
| .83 .081 .58 .82 .21 |
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 = | 7.5 -16 -9.2 12 14 |
| -2.1 4 2.2 -1.6 -4.1 |
| 3.6 -4.2 -4.2 3.2 4.3 |
| -9.4 18 11 -13 -15 |
| -1.9 3.5 4 -4.1 -3.2 |
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 = 5.10702591327572e-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 = | 7.5 -16 -9.2 12 14 |
| -2.1 4 2.2 -1.6 -4.1 |
| 3.6 -4.2 -4.2 3.2 4.3 |
| -9.4 18 11 -13 -15 |
| -1.9 3.5 4 -4.1 -3.2 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|