(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 = | .59+.55i .18+.87i .19+.42i .29+.61i .08+.76i .89+.1i .78+.23i
| .11+.26i .82+.72i .52+.43i .79+.47i .72+.83i .93+.37i .46+.76i
| .67+.29i .69+.06i .89+.08i .41+.57i .6+.58i .19+.54i .98+.46i
| .08+.7i .92+.08i .02+.84i .42+.65i .41+.15i .65+.66i .25+.58i
| .32+.29i .78+.22i .38+.17i .12+.84i .61+.73i .82+.55i .95+.69i
| .64+.08i .85+.32i .32+.29i .19+.91i .89+.7i .75+.17i .44+.73i
| .42+.072i .69+.18i .7+.99i .15+.69i .38+.055i .5+.58i .059+.45i
| .65+.95i .43+.42i .03+.94i .7+.88i .35+.56i .63+.09i .31+.35i
| .7+.45i .08+.98i .09+.85i .67+.84i .46+.38i .73+.53i .09+.57i
| .56+.08i .94+.02i .38+.18i .2+.56i .95+.13i .65+.64i .16+.62i
-----------------------------------------------------------------------
.25+.34i .99+.48i .56+.7i |
.52+.97i .38+.21i .26+.096i |
.15+.93i .55+.08i .34+.94i |
.36+.006i .53+.19i .03+.99i |
.84+.42i .81+.12i .83+.7i |
.57+.46i .78+.94i .85+.02i |
.35+.2i .22+.47i 1+.05i |
.17+.06i .49+.3i .12+.87i |
.53+.72i .7+.6i .61+.36i |
.51+.71i .5+.49i .05+.0023i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .95+.75i .49+.42i |
| .061+.44i .1+.74i |
| .45+.087i .36+.36i |
| .74+.4i .11+.54i |
| .54+.12i .35+.88i |
| .98+.07i .62+.2i |
| .25+.34i .81+.6i |
| .21+i .4+.93i |
| .71+.2i .75+.48i |
| .5+.99i .67+.7i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -1.7+.51i -.3+.52i |
| -.69-2.8i -1.3-1.7i |
| 2.2+2.4i 2.1+.73i |
| -.97-1.5i -1-i |
| 3.2+2.7i 2.6+1.2i |
| 1.6+1.8i 1.2+.57i |
| -2-.67i -.86-.05i |
| -2+1.1i -.55+1.3i |
| .44+.1i -.42+.19i |
| .67-2.9i -.33-1.3i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 2.86568757593482e-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 = | .96 .23 .18 .25 .63 |
| .023 .92 .67 .5 .75 |
| .53 .17 .49 .82 .87 |
| .47 .46 .77 .82 .79 |
| .74 .53 1 .8 .7 |
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 = | 6 -7.7 -20 39 -16 |
| 15 -19 -55 110 -47 |
| -17 23 63 -130 57 |
| 20 -30 -80 160 -70 |
| -16 24 64 -130 53 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 1.77635683940025e-14
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 2.66453525910038e-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 = | 6 -7.7 -20 39 -16 |
| 15 -19 -55 110 -47 |
| -17 23 63 -130 57 |
| 20 -30 -80 160 -70 |
| -16 24 64 -130 53 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|