(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 = | .62+.93i .71+.53i .46+.052i .93+.61i .36+.62i .27+.18i
| .33+.36i .29+.21i .76+.47i .92+.49i .55+.76i .61+.02i
| .081+.21i .04+.94i .56+.34i .87+.07i .96+.64i .15+.061i
| .41+.36i .78+.99i .13+.71i .4+i .15+.61i .94+.31i
| .15+.045i .57+.12i .55+.93i .97+.31i .071+.094i .69+.56i
| .1+.2i .23+.47i .92+.74i .36+.94i .69+.42i .64+.22i
| .25+.22i .2+.12i .85+.76i .26+.5i .77+.11i .4+.23i
| .53+.67i .69+.83i .83+.5i .26+.97i .58+.51i .92+.64i
| .29+.12i .045+.41i .42+.23i .096+.26i .085+.29i .19+.95i
| .59+.22i .066+.23i .56+.31i .24+.4i .42+.97i .11+.056i
-----------------------------------------------------------------------
.45+.52i .6+.39i .07+.68i .8+.38i |
.94+.36i .91+.51i .72+.51i .74+.68i |
.42+.8i .12+.5i .7+.51i .14+.51i |
.03+.056i .11+.68i .64+.6i .57+.86i |
.87+.91i .67+.2i .46+.51i .57+.3i |
.39+.19i .79+.83i .74+.38i .006+.097i |
.44+.49i .99+.18i .87+.97i .29+.62i |
.16+.58i .19+.99i .52+.26i .65+.35i |
.96+.6i .07+.77i .12+.97i .59+.61i |
.92+.23i .55+.97i .46+.14i .096+.35i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .37+.98i .81+.6i |
| .91+.37i .39+.66i |
| .79+.07i .07+.87i |
| .67+.71i .45+.5i |
| .14+.49i .73+.76i |
| .6+.91i .21+.24i |
| .94+.94i .31+.19i |
| .35+.19i .68+.1i |
| .06+.84i .03+.37i |
| .33+.71i .33+.29i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.48-.027i .19-.36i |
| .56+i .78-.31i |
| .71i .21-.44i |
| .53-.42i -.32+.36i |
| .6-.66i -.034-.48i |
| -.18-.75i -.032-.28i |
| -.22+.39i .24+.036i |
| -.44+.34i .22+.65i |
| 1.1-.24i -.14+.26i |
| -.45-.5i .022+.28i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 6.95552731308039e-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 = | .78 .69 .17 .04 .92 |
| .17 .68 .33 .67 .28 |
| .61 .62 1 .38 .54 |
| .83 .38 .63 .12 .68 |
| .39 .83 .43 .25 .72 |
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.8 -.075 7 -7.4 -8.3 |
| 10 -1.4 11 -13 -7.9 |
| -1.9 -.81 .27 .99 1.6 |
| -6.4 2.9 -7.2 8.6 4.3 |
| -13 1.2 -14 16 12 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 1.77635683940025e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 3.5527136788005e-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.8 -.075 7 -7.4 -8.3 |
| 10 -1.4 11 -13 -7.9 |
| -1.9 -.81 .27 .99 1.6 |
| -6.4 2.9 -7.2 8.6 4.3 |
| -13 1.2 -14 16 12 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|