(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 = | .42+.6i .23+.49i .1+.75i .48+.55i .46+.67i .59+.19i .11+.98i
| .88+.21i .13+.38i .4+.89i .87+.8i .63+.87i .49+.16i .66+.61i
| .08+.68i .7+.74i .98+.79i .62+.76i .64+.14i .62+.12i .38+.95i
| .77+.85i .96+.26i .27+.59i .16+.04i .26+.72i .62+.89i .58+.17i
| .37+.99i .25+.06i .93+.52i .21+.84i .95+.66i .18+.29i .72+.45i
| .89+.59i .11+.17i .56+.31i .72+.92i .63+.98i .81+.37i .91+.18i
| .75+.04i .34+.15i .63+.63i .66+.84i .86+.63i .96+.03i .9+.25i
| .97+.54i .09+.59i .69+.73i .78+.57i 1+.83i .57+.24i .23+.47i
| .01+.83i .89+.23i .046+.0071i .08+.66i .97+.7i .23+.15i .91+.2i
| .73+.03i .02+.57i .36+.79i .39+.51i .55+.04i .03+.47i .46+.31i
-----------------------------------------------------------------------
.81+.17i .68+.07i .31+.83i |
.88+.79i .9+.26i .92+.18i |
.71+.25i .99+.14i .73+.74i |
.44+.63i .51+.18i .33+.84i |
.78+.4i .45+.99i .13+.38i |
.84+.4i .16+.9i .84+.79i |
.95+.18i 1+.36i .42+.62i |
.48+.79i .84+.76i .92+.63i |
.78+.34i .99+.12i .6+.95i |
.86+.75i .17+.85i .91+.95i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .11+.1i .94+.29i |
| .62+.82i .68+.63i |
| .21+.86i .53+.33i |
| .68+.72i .66+.03i |
| .97+.17i .097+.011i |
| .36+.97i .17+.53i |
| .63+i .84+.51i |
| .35+.51i .08+.94i |
| .56+.14i .3+.76i |
| .78+.47i .47+.74i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.09-2.2i -5.7+1.5i |
| -1.8-.46i -1.9+8.1i |
| .39-1.1i -2-.37i |
| -1.1+2i 5.2+4.5i |
| -1.5+.55i 2.2+2.1i |
| .64+2.4i 2.5-4.6i |
| 1.1+1.7i 2-4.6i |
| 2-1.1i -1.4-2.2i |
| .87-.12i 1.4-1.9i |
| .063-.11i .69-1.5i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 4.45336459267844e-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 = | .24 .048 .98 .48 .38 |
| .83 .74 .19 .43 .53 |
| .52 .72 .38 .44 .79 |
| .32 .025 .69 .41 .45 |
| .88 .78 .64 .076 .021 |
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.9 .61 -1.3 4 .7 |
| 2.5 .091 1.2 -4.3 .08 |
| .36 -1.4 .58 .3 .76 |
| 5.3 4.3 -2.3 -5.5 -2.2 |
| -3.5 -2.2 2.1 4.2 .28 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 1.33226762955019e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 1.94289029309402e-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 = | -2.9 .61 -1.3 4 .7 |
| 2.5 .091 1.2 -4.3 .08 |
| .36 -1.4 .58 .3 .76 |
| 5.3 4.3 -2.3 -5.5 -2.2 |
| -3.5 -2.2 2.1 4.2 .28 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|