(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 = | .67+.55i .44+.47i .63+.44i .47+.55i .27+.71i .46+.72i .36+.51i
| .56+.94i .26+.46i .71+.44i 1+.56i .57+.16i .56+.58i .1+.82i
| .68+.7i .56+.52i .68+.96i .31+.26i .86+.46i .64+.44i .94+.45i
| .68+.22i .9+.16i .52+.82i .26+.99i .97+.87i .11+.79i .31+.097i
| .58+.51i .12+.24i .84+.27i .03+.6i .22+.7i .5+.074i .8+.97i
| .39+.26i .79+.99i .95+.07i .38+.76i .67+.96i .94+.48i .37+.37i
| .11+.69i .56+.03i .98+.68i .81+.08i .69+.6i .08+.56i .47+.28i
| .57+.23i .43+.75i .92+.37i .39+.71i .27+.8i .84+.7i .23+.86i
| .22+.35i .21+.36i .78+.19i .38+.61i .88+.88i .16+.56i .94+.43i
| .94+.53i .11+.15i .8+.36i .77+.51i .47+.35i .37+.34i .24+.39i
-----------------------------------------------------------------------
.5+.95i .21+.81i .1+.99i |
.28+.2i .28+.071i .77+.6i |
.67+.86i .22+.86i .03+.66i |
.78+.14i .88+.85i .18+.65i |
.01+.46i .42+.44i 1+.34i |
.18+.29i .15+.6i .98+.34i |
.76+.8i .66+.13i .25+.61i |
.09+.15i .36+.69i .48+.46i |
.46+.58i .57+.27i .83+.24i |
.83+.08i .22+.24i .55+.1i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .85+.73i .75+.87i |
| .14+.25i .51+.4i |
| .75+.58i .88+.84i |
| .34+.23i .67+.81i |
| .11+.12i .2+.92i |
| .36+.072i .69+.43i |
| .43+.35i .95+.83i |
| .98+.22i .52+.22i |
| .7+.78i .83+.49i |
| .061+.34i .98+.19i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -1.4+.19i .93+1.7i |
| .21-.032i .12-1.1i |
| -.12+.72i .72-.21i |
| .21-.3i -1.1-.2i |
| -1.2+1.1i 1.3+.87i |
| .64-1.4i -.47+.18i |
| 1.3-.59i -1.6-1.3i |
| 1.3+.33i 1.2-2.1i |
| .32-i .1+1.5i |
| -.23+.26i -.055+.43i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 8.00593208497344e-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 = | .38 .95 .029 .21 .99 |
| .14 .76 .52 .9 .55 |
| .26 .81 .6 .16 .98 |
| .4 .19 .12 .96 .15 |
| .037 .13 .34 .64 .8 |
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 = | -.3 -2.1 1.9 2.4 -.97 |
| .67 1.4 -.51 -.68 -1 |
| -1.6 -.072 2 .34 -.38 |
| .12 .71 -.93 .21 .45 |
| .51 -.66 -.11 -.31 1.3 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 2.77555756156289e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 4.71844785465692e-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 = | -.3 -2.1 1.9 2.4 -.97 |
| .67 1.4 -.51 -.68 -1 |
| -1.6 -.072 2 .34 -.38 |
| .12 .71 -.93 .21 .45 |
| .51 -.66 -.11 -.31 1.3 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|