(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 = | .16+.27i .38+.89i .92+.05i .1+.8i .06+.65i .78+.84i .22+.74i
| .59+.73i .86+.79i .71+.35i .36+.41i .07+.74i .32+.25i .29+.072i
| .73+.72i .84+.08i .34+.1i .97+.2i .7+.05i .68+.4i .63+.31i
| .44+.24i .65+.5i .46+.5i .49+.17i .26+.27i .92+.76i .34+.82i
| .96+.35i .87+.19i .14+.98i .7+.55i .66+.06i .55+.22i .54+.9i
| .4+.55i .48+.94i .11+.85i .69+.35i .72+.19i .76+.88i .48+.35i
| .63+.13i .31+.44i .27+.52i .32+.52i .55+.14i .28+.77i .44+.17i
| .21+.33i .72+.95i .85+.6i .75+.54i .03+.8i .84+.01i .41+.8i
| .06+.67i .61+.12i .18+.38i .8+.89i .7+.28i .47+.054i .53+.55i
| .07+.99i .79+.39i .12+.46i .93+.54i .03+.7i .96+.64i .11+.17i
-----------------------------------------------------------------------
.052+.44i .21+.86i .31+.14i |
.56+.09i .58+.73i .91+.1i |
.22+.21i .41+.9i .29+.62i |
.044+.29i .027+.23i .22+.23i |
.35+.36i .84+.44i .73+.05i |
.79+.64i .78+.58i .34+.66i |
.52+.25i .25+.71i .25+.76i |
.57+.04i .56+.14i .85+.8i |
.14+.66i .28+.61i .89+.53i |
.77+.46i .19+.79i .57+.76i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .71+.65i .54+.3i |
| .38+.88i .66+.84i |
| .6+.94i .87+.68i |
| .8+.52i .28+.15i |
| .72+.41i .46+.47i |
| .57+.8i .59+.49i |
| .19+.94i .15+.78i |
| .055+.14i .25+.095i |
| .052+.13i .4+.63i |
| .99+.35i .21+.66i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.53+.03i .28+.2i |
| .76+.98i .25-.38i |
| -.2+.14i .95-.32i |
| -.6+.43i .77+.25i |
| -.57-.01i .37+.2i |
| .43-1.1i .001+.41i |
| .21-.4i -1.2+.76i |
| .21+.049i -.97-.83i |
| .86-.26i .51-.36i |
| .18+.091i -.34-.007i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 8.89911452410874e-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 = | .79 .24 .3 .67 .46 |
| .54 .33 .22 .92 .1 |
| .19 .55 .25 .4 .63 |
| .36 .59 .68 .092 .26 |
| .74 .45 .14 .12 .84 |
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 = | -.57 1 -2 .3 1.6 |
| -4.2 2.9 -.55 .63 2.2 |
| 3 -2.3 .68 1.1 -2.2 |
| .9 .21 .98 -.59 -1.1 |
| 2.1 -2.1 1.8 -.71 -.83 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 5.68989300120393e-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 = | -.57 1 -2 .3 1.6 |
| -4.2 2.9 -.55 .63 2.2 |
| 3 -2.3 .68 1.1 -2.2 |
| .9 .21 .98 -.59 -1.1 |
| 2.1 -2.1 1.8 -.71 -.83 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|