(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 = | .19+.87i .93+.71i .02+.52i .1+.92i .2+.91i .14+.45i .47+.39i
| .45+.33i .36+.66i .97+.13i .64+.15i .32+.057i .61+.55i .1+.073i
| .16+.93i .11+.18i .9+.23i .29+.12i .85+.64i .57+.45i .23+.84i
| .91+.91i .36+.043i .61+.12i .71+.07i .52+.47i .71+.62i .88+.44i
| .4+.26i .58+.08i .28+.53i .36+.092i .82+.66i .14+.22i .84+.95i
| .93+.62i .78+.23i .04+.54i .58+.9i .17+.68i .69+.08i .32+.21i
| .82+.16i .89+.71i .97+.35i .74+.04i .41+.2i .46+.34i .2+.58i
| .89+.76i .53+.19i .89+.87i .1+.001i .49+.7i .76+.82i .83+.86i
| .74+.73i .83+.37i .87+.53i .15+.31i .82+.65i .94+.29i .48+.074i
| .69+.76i .17+.49i .51+.97i .39+.93i .98+.68i .16+.075i .086+.32i
-----------------------------------------------------------------------
.23+.44i .35+.81i .76+i |
.83+.16i .78+.23i .82+.82i |
.042+.011i .71+.81i .66+.06i |
.22+.4i .009+.064i .32+.35i |
.17+.095i .72+.51i .14+.78i |
.8+.92i .41+.57i .51+.75i |
.67+.13i .06+.51i .15+.46i |
.87+.15i .48+.52i .55+.92i |
.77+.34i .87+.67i .83+.12i |
.79+.91i .15+.87i .41+.44i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .35+.84i .2+.87i |
| .6+.44i .98+.62i |
| .56+.47i .5+.21i |
| .47+.75i .91+.05i |
| .28+.83i .52+.86i |
| .87+.54i .64+.42i |
| .36+.81i .29+.13i |
| .96+.68i .51+.18i |
| .62+.88i .41+.7i |
| .61+.41i .1+.43i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .74-.97i -1-.84i |
| .21+.82i .27+.25i |
| .42-.41i -.88-.37i |
| -.24+.41i .85-.06i |
| -.2+.93i 1.2+.98i |
| 1.1i 1.7+.17i |
| -.54-.06i -.36+.054i |
| -.48+.036i .19+.75i |
| -.036-.27i -.33+.59i |
| .6-.99i -.18-.98i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 7.7715611723761e-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 = | .077 .2 .23 .98 .96 |
| .37 .44 .35 .93 .95 |
| .17 .2 .051 .32 .34 |
| .95 .71 .87 .27 .68 |
| .024 .023 .22 .82 .19 |
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 = | 15 -34 38 6.5 3.8 |
| -21 41 -38 -7.6 -4 |
| -3.5 10 -16 -.83 -.59 |
| -.15 -1.1 2.8 -.075 1.6 |
| 5.3 -7.3 6.1 1.4 -.93 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 3.5527136788005e-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 = | 15 -34 38 6.5 3.8 |
| -21 41 -38 -7.6 -4 |
| -3.5 10 -16 -.83 -.59 |
| -.15 -1.1 2.8 -.075 1.6 |
| 5.3 -7.3 6.1 1.4 -.93 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|