(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 = | 0 |
| -3.3e-16 |
| -8.9e-16 |
3 1
o10 : Matrix RR <--- RR
53 53
|
i11 : norm oo
o11 = 8.88178419700125e-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 = | .77+.22i .35+.36i 1+.92i .031+.44i .6+.51i .76+.31i .76+.62i
| .3+.34i .51+.15i .07+.56i .45+.36i .76+.6i .84+.51i .86+.02i
| .86+.33i .85+.32i .18+.34i .06+.72i .42+.024i .71+.22i .84+.67i
| .53+.57i .97+.79i .97+.63i .48+.4i .48+.98i .54+.7i .9+.57i
| .54+.51i .68+.8i .76+.41i .85+.69i .96+.53i .02+.9i .67+.09i
| .38+.92i .51+.81i .65+.87i .5+.79i .96+.91i .21+.86i .96+.45i
| .13+.94i .33+.19i .65+.23i .17+.81i .69+.05i .35+.42i .65+.8i
| .81+.09i .71+.49i .67+.45i .63+.75i .61+.3i .24+.68i .25+.028i
| .42+.27i .41+.78i .14+.99i .059+.32i .27+.23i .23+.38i .34+.11i
| .87+.94i .22+.93i .32+.11i .95+.1i .73+.79i .09+.63i .46+.45i
-----------------------------------------------------------------------
.85+.81i .58+.14i .64+.05i |
.73+.13i .76+.48i .99+.34i |
.46+.97i .26+.24i .95+.07i |
.88+.57i .4+.29i .064+.06i |
.8+.63i .01+.71i .65+.27i |
.45+.95i .95+.64i .84+.93i |
.3+.72i .79+.64i .12+.99i |
.97+.2i .15+.23i .42+.46i |
.57+.9i .73+.87i .33+.89i |
.76+.32i .11+.31i .59+.62i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .05+.98i .14+.86i |
| .39i .87+.4i |
| .94+.01i .14+.42i |
| .81+.6i .44+.11i |
| 1+.6i .087+.01i |
| .29+.77i .52+.34i |
| .67+.65i .81+.73i |
| .88+.4i .64+.51i |
| .59+.17i .78+.62i |
| .72+.79i .11+.18i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .13-.39i -1.2+.2i |
| .73-.94i .21-.89i |
| .3+.019i -.49-i |
| .24-.22i .61-.19i |
| -.22+.85i .18+1.2i |
| .27+.45i .43+.26i |
| .29+.083i .85-.48i |
| -.15+.4i .61+.82i |
| -.53-.23i -.18+.92i |
| -.089-.26i -.28-.89i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 4.96506830649455e-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 = | .23 .24 .52 .88 .13 |
| .16 .81 .26 .56 .4 |
| .79 .69 .016 .94 .91 |
| .14 .4 .61 .96 .31 |
| .89 .37 .13 1 .1 |
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 = | 72 9.7 8.1 -62 -17 |
| -.58 2 -.7 -.45 .48 |
| 100 14 11 -85 -24 |
| -79 -11 -8.7 68 19 |
| 17 1.5 3.4 -14 -5.4 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 2.1316282072803e-14
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 1.4210854715202e-14
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 = | 72 9.7 8.1 -62 -17 |
| -.58 2 -.7 -.45 .48 |
| 100 14 11 -85 -24 |
| -79 -11 -8.7 68 19 |
| 17 1.5 3.4 -14 -5.4 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|