(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 = | -1.1e-16 |
| -7.8e-16 |
| 0 |
3 1
o10 : Matrix RR <--- RR
53 53
|
i11 : norm oo
o11 = 7.7715611723761e-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 = | .54+.79i .061+.16i .41+.92i .74+.94i .75+.24i .22+.24i .45+.56i
| .46+.51i .38+.69i .24+.76i .12+.83i .48+.65i .42+.75i .93+.32i
| .55 .44+.22i .88+.36i .17+.59i .91+.18i .15+.39i .67+.53i
| .19+.85i .11+.79i .88+.35i .39+.26i .041+.038i .65+.96i .47+.92i
| .46+.61i .65+.31i .18+.056i .71+.43i .38+.69i .69+.57i .82+.42i
| .78+.42i .32+.29i .17+.72i .63+.15i .03+.79i .39+.66i .38+.2i
| .94+.47i .97+.01i .36+.05i .59+.84i .97+.95i .22+.3i .6+.42i
| .08+.9i .78+.01i .44+.75i .83+.4i .43+.68i .27+.49i .14+.24i
| .28+.64i .69+.08i .04+.62i .36+.68i .22+.66i .97+.85i .18+.87i
| .65+.03i .48+.094i .69+.09i .72+.65i .45+.37i .18+.22i .59+.47i
-----------------------------------------------------------------------
.45+.81i .84+.08i .19+.72i |
.41+.17i .32+.24i .07+.57i |
.2+.12i .84+.07i .58+.89i |
.38+.89i .5+.83i .95+.94i |
.98+.95i .73+.4i .24+.9i |
.014+.087i .99+.82i .91+.85i |
.061+.18i .84+.81i .71+.07i |
.42+.34i .85+.56i .22+.095i |
.33+.074i .17+.45i .035+.3i |
.12+.33i .23+.7i .96+.05i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .69+.68i .71+.49i |
| .43+.89i .59+.12i |
| .88+.24i .69+.22i |
| .11+.24i .14+.42i |
| .41+.32i .45+.012i |
| .38+.67i .94+.11i |
| .29+.45i .6+.46i |
| .79+.5i .65+.51i |
| .12+.56i .9+.47i |
| .69+.07i .44+.8i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .14+.46i -.31+.44i |
| .26+.99i -1.1-.23i |
| 1.1-.68i .38+.58i |
| -.3-.37i 1.1-.88i |
| -.54-.15i -.4-.66i |
| -.25-.19i .37-.35i |
| .18+.51i -.18-.41i |
| .43-.36i .14+1.2i |
| .043-.0085i 1+.2i |
| -.095-.042i -.45+.059i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.00534970772086e-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 = | .2 .052 .33 .71 1 |
| .59 .89 1 .57 .52 |
| .29 .83 .42 .61 .41 |
| .59 .69 .39 .76 .69 |
| .58 .63 .0095 .37 .68 |
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 = | -1.2 .36 -3 3.3 -.057 |
| -.22 -.05 2.1 -2 1.1 |
| .37 1.4 -.45 -.75 -.55 |
| -.3 -1.4 .19 3.5 -2.2 |
| 1.3 .45 .5 -2.8 1.7 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 2.27248775352962e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 1.11022302462516e-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 = | -1.2 .36 -3 3.3 -.057 |
| -.22 -.05 2.1 -2 1.1 |
| .37 1.4 -.45 -.75 -.55 |
| -.3 -1.4 .19 3.5 -2.2 |
| 1.3 .45 .5 -2.8 1.7 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|