(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 = | .44+.5i .07+.52i .75+.83i .66+.33i .17+.26i .71+.15i .83+.11i
| .95+.98i .27+.008i .61+.73i .32+.031i .24+.039i .4+.32i .62+.65i
| .65+.63i .72+.47i .36+.63i .45+.76i .044+.45i .068+.45i .51+.23i
| .06+.87i .12+.45i .53+.09i .87 .28+.91i .27+.63i .11+.34i
| .92+.7i .71+.66i .17+.69i .29+.99i .86+.93i .41+.011i .051+.38i
| .95+.57i .66+.09i .33+.61i .69+.02i .69+.41i .76+.78i .59+.67i
| .41+.8i .21+.82i .99+.26i .75+.13i .81+.03i .07+.71i .7+.79i
| .57+.73i .29+.2i .05+.6i .68+.89i .8+.16i .026+.47i .38+.83i
| .75+.03i .99+.64i .046+.016i .69+.33i .75+.68i .81+.43i .31+.82i
| .38+.5i .39+.23i .83+.22i .84+.93i .15+.71i .45+.31i .95+.24i
-----------------------------------------------------------------------
.01+.74i .28+.81i .25+.8i |
.48+.13i .25+.9i .99+.86i |
.45+.76i .6+.74i .97+.01i |
.95+.2i .99+.25i .39+.47i |
.28+.25i .45+.95i .37+.14i |
.75+.24i .69+.37i .28+.67i |
.13+.051i .94+.1i .5+.96i |
.056+.24i .59+.2i .55+.48i |
.96+.2i .73+.07i .27+.95i |
.75+.74i .078+.009i .65+.54i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .68+.73i .87+.41i |
| .78+.39i .4+.21i |
| .76+.8i .64+.53i |
| .21+.32i .76+.04i |
| .37+.22i .45+.99i |
| .64+.98i .13+.31i |
| .43+.9i .73+.04i |
| .12+.097i .91+.77i |
| .41+.69i .9+.65i |
| .58+.26i .75+.25i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | 1.3-2.1i .87-1.8i |
| 1.3-.79i .61-1.2i |
| -1.3-.95i -1.4-.52i |
| -.21-2.4i 1.5-1.7i |
| -2.8+2i -2.8+1.5i |
| -.97+.78i -.51+2.1i |
| 2.2+3.5i 1.6+.99i |
| 2+3.5i 1.2+2.4i |
| 1.9+.53i 1.7+.57i |
| -2.6-1.9i -1.9-.79i |
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 = | .44 .87 .37 .7 .27 |
| .99 .48 .075 .63 .61 |
| .91 .33 .033 .28 .28 |
| .14 .45 .73 .049 .04 |
| .53 .47 .15 .91 .67 |
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 = | -.73 -3.7 4.4 .18 1.8 |
| 2.7 8.8 -7.3 -.73 -5.9 |
| -1.5 -4.7 3.7 1.8 3.2 |
| -.73 -11 8.5 -.3 6.7 |
| -.0072 13 -11 .36 -5.6 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 8.88178419700125e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 2.42254133420161e-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 = | -.73 -3.7 4.4 .18 1.8 |
| 2.7 8.8 -7.3 -.73 -5.9 |
| -1.5 -4.7 3.7 1.8 3.2 |
| -.73 -11 8.5 -.3 6.7 |
| -.0072 13 -11 .36 -5.6 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|