(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 = | .83+.3i .83+.29i .21+.6i .82+.5i .93+.8i .19+.016i .9+.68i
| 1+.08i .091+.034i .32+.97i .47+.23i .22+.42i .95+.23i .85+.17i
| .6+.4i .69+.38i .88+.51i .57+.35i .74+.49i .18+.58i .48+.27i
| .85+.94i .26+.98i .56+.98i .04+.96i .36+.39i .95+.55i .32+.27i
| .1+.89i .97+.42i .74+.97i 1+.07i .19+.22i .68+.45i .54+.96i
| .26+.11i .065+.25i .87+.44i .033+.089i .18+i .51+.45i .27+.38i
| .087+.13i .29+.41i .65+.34i .33+.21i .58+.49i .37+.84i .51+.41i
| .83+.66i .64+.47i .33+.25i .92+.72i .18+.48i .85+.01i .19+.77i
| .62+.38i .61+.58i .21+.58i .11+.012i .5+.91i .28+.19i .71+.79i
| .18+.85i .26+.085i .58 .2+.71i .72+.79i .93+.19i .78+.55i
-----------------------------------------------------------------------
.092+.12i 1+.54i .097+.016i |
.87+.09i .54+.86i .79+.45i |
.46+.79i .68+.81i .62+.66i |
.54+.62i .13+.83i .28+.9i |
.95+.68i .43+.41i .35+.5i |
.88+.14i .6+.61i .08+.67i |
.98+.77i .16+.54i .59+.29i |
.78+.49i .01+.85i .48+.28i |
.96+.96i .28+.54i .02+.73i |
.2+.47i .04+.18i .07+.91i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .49+.42i .51+.2i |
| .31+.33i .37+.4i |
| .46+.27i .98+.7i |
| .95+.6i .6+.05i |
| .27+.36i .52+.72i |
| .57+.29i .11+.41i |
| .21+.78i .89+i |
| .98+.86i .43+.58i |
| .15+.77i .52+.91i |
| .8+.04i .38+.18i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .51+.5i -.04-.1i |
| -.98+1.5i 1.3i |
| 1.8-.71i 1.1-.74i |
| -1.2-.09i -1.8+.59i |
| 2.6+2.1i 2.3+1.3i |
| .58+1.1i .6+.71i |
| -1.3-2.6i -.91-1.6i |
| -.064+.067i -.28-.53i |
| -.71-1.9i -.45-1.7i |
| -1.3+.55i .02+1.2i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 2.00148302124336e-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 = | .63 .18 .079 .27 .63 |
| .026 .32 .22 .11 .099 |
| .93 .34 .92 .34 .84 |
| .72 .97 .24 .79 .67 |
| .42 .77 .49 .33 .24 |
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 = | .8 -5.9 -.21 -.78 3.3 |
| 2.3 2.5 -1.5 -1.3 2 |
| -2.1 .25 1.5 .31 -.65 |
| -5 -3.4 1.9 3.9 -3.2 |
| 2.5 6.6 -.33 -.54 -2.5 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 1.11022302462516e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 8.88178419700125e-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 = | .8 -5.9 -.21 -.78 3.3 |
| 2.3 2.5 -1.5 -1.3 2 |
| -2.1 .25 1.5 .31 -.65 |
| -5 -3.4 1.9 3.9 -3.2 |
| 2.5 6.6 -.33 -.54 -2.5 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|