(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 = | .92+.57i .37+.4i .93+.84i .53+.09i .51+.09i .76+.1i .43+.25i
| .38+.86i .29+.84i .18+.6i .77+.53i .49+.44i .8+.57i .45+.053i
| .68+.62i .24+.42i .14+.072i .44+.063i .11+.96i .46+.2i .4+.71i
| .26+.31i .78+.63i .38+.043i .094+.43i .83+.55i .71+.86i .04+.46i
| .22+i .59+.21i .96+.37i .29+.67i .36+.75i .46+.66i .67+.21i
| .27+.89i .45+.93i .86+.17i .91+.92i .78+.69i .94+.08i .78+.16i
| .86+.56i .75+.16i .56+.65i .32+.67i .13+.21i .081+.49i .73+.77i
| .11+.74i .96+.35i .58+.87i .66+.98i .14+.27i .7+.42i .2+.47i
| .58+.92i .3+.52i .33+i .87+.29i .91+.49i .74+.28i .81+.09i
| .17+.2i .1+.94i .47+.56i .01+.54i .43+.89i .39+.89i .06+.64i
-----------------------------------------------------------------------
.07+.85i .75+.31i .068+.11i |
.85+.87i .46+.071i .07+.86i |
.91+.72i .8+.02i .93+.56i |
.35+.22i .81+.1i .06+.76i |
.34+.36i .78+.15i .23+.24i |
.63+.63i .4+.92i .65+.9i |
.011+.054i .64+.49i .15+.45i |
.49+.88i .8+.97i .25+.49i |
.95+.12i .54+.15i .63+.25i |
.09+.81i .33+.035i .97+.46i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .21+.8i .66+.1i |
| .01+.63i .2+.47i |
| .79+.91i .91+.14i |
| .92+.14i .24+.67i |
| .24+.58i .98+.16i |
| .58+.51i .03+.78i |
| .4+.8i .096+.23i |
| .54+.68i .43+.65i |
| .24+.85i .87+.42i |
| .85+.81i .8+.47i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .63+.86i -.04-.91i |
| -.9-.98i -.68+.68i |
| -.013+.44i .34+.059i |
| -.54-1.1i -1.2+.52i |
| -1.1+.23i .14+1.1i |
| 1.5-.26i .31-i |
| -.22-.036i .078+.22i |
| .47+1.1i .63-.29i |
| 1.3-.35i .51-.41i |
| .35+.81i 1.2+.2i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 9.42055475210265e-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 = | .45 .26 .57 .55 .94 |
| .38 .98 .38 .45 .99 |
| .8 .6 .093 .84 .4 |
| .39 .2 .76 .51 .46 |
| .16 .84 .61 .78 .31 |
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 = | -2 .96 1.1 2.4 -1.9 |
| -1.7 1.3 .029 .57 .023 |
| -1.2 .4 -.59 2.3 -.23 |
| 2.4 -1.9 .36 -2.3 1.8 |
| 1.8 .065 -.4 -1.3 -.032 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 4.44089209850063e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 4.44089209850063e-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 = | -2 .96 1.1 2.4 -1.9 |
| -1.7 1.3 .029 .57 .023 |
| -1.2 .4 -.59 2.3 -.23 |
| 2.4 -1.9 .36 -2.3 1.8 |
| 1.8 .065 -.4 -1.3 -.032 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|