(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 = | .21+.4i .33+.71i .87+.14i .44+.2i .9+.49i .89+.26i .74+.15i
| .088+.008i .7+.75i .56+.85i .2+.97i .15+.12i .72+.43i .43+.16i
| .33+.44i .24+.92i .37+.16i .96+.03i .84+.71i .23+.44i .78+.93i
| .003+.2i .43+.47i .15+.27i .17+.69i .62+.99i .64+.19i .03+.64i
| .16+.7i .73+.71i .21+.36i .19+.78i .97+.04i .57+.75i .08+.68i
| .74+.37i .74+.73i .24+.56i .15+.85i .54+.38i .38+.88i .53+.35i
| .42+.23i .13+.94i .37+.97i .84+.92i .68+.3i .65+.76i .39+.12i
| .23+.7i .21i .018+.41i .58+.57i .37+.079i .08+.96i .89+.01i
| .12+.73i .07+.53i .4+.72i .72+.38i .62+.81i .43+.44i .94+.33i
| .8+.82i .64+.36i .95+.81i .66+.43i .75+.27i .87+.5i .29+.65i
-----------------------------------------------------------------------
.031+.44i .24+.76i .58+.66i |
.8+.6i .47+.38i .77+.12i |
.07+.97i .19+.38i .46+.58i |
.09+.78i .73+.98i .055+.44i |
.25+.66i .42+.14i .47+.45i |
.63+.74i .9+.4i .34+.33i |
.48+.1i .13+.18i .15+.032i |
.63+.72i .19+.47i .27+.61i |
.65+.12i .71+.97i .19+.46i |
.39+.024i .77+.64i .79+.55i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .24+.26i .46+.52i |
| .28+.78i .081+.33i |
| .87+.71i .89+.63i |
| .14+.072i .63+.03i |
| .81+.69i .58+.87i |
| .69+.94i .92+.12i |
| .59+.24i .39+.94i |
| .47+.85i .49+.95i |
| .63+.52i .16+.45i |
| .011+.096i .75+.89i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.51-.44i .77-.61i |
| 1.1-.65i -.39-.043i |
| -1.7+.7i .62+.31i |
| .71+.09i .08+.71i |
| -.79-.64i -.2+.23i |
| .9-.72i .87-.28i |
| .94+.05i -.47-.15i |
| -.68+.91i .44-1.3i |
| .36+.69i .2+.058i |
| .55+.14i -1+.67i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.15910686703364e-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 = | .71 .74 .87 .48 .84 |
| .2 .66 .72 .31 .35 |
| .28 .11 .013 .64 .25 |
| .15 .21 .47 .037 .14 |
| .97 .65 .076 .37 .13 |
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 = | .21 -1.8 .11 2.3 .86 |
| -.17 2.6 -1.2 -3.7 .53 |
| -.62 -.45 .61 4 -.26 |
| -1 .61 2 .89 -.11 |
| 2.4 -.6 -.79 -3.4 -.87 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 4.9960036108132e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 6.66133814775094e-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 = | .21 -1.8 .11 2.3 .86 |
| -.17 2.6 -1.2 -3.7 .53 |
| -.62 -.45 .61 4 -.26 |
| -1 .61 2 .89 -.11 |
| 2.4 -.6 -.79 -3.4 -.87 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|