(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 = | .38+.47i .6+.54i .35+.72i .94+.1i .51+.76i .88+.25i .37+.02i
| .62+.91i .69+.34i .61+.08i .16+.006i .17+.9i .83+.99i .12+.28i
| .66+.11i .25+.12i .66+.91i .1+.64i .21+.12i .96+.39i .25+.38i
| .81+.09i .69+.69i .87+.38i .32+.71i .23+.41i .78+.64i .69+i
| .86+.53i .83+.15i .37+.22i .59+.43i .97+i .43+.22i .19+.97i
| .27+.64i .096+.13i .66+.54i .28+.2i .59+.7i .89+.83i .67+.41i
| .94+.04i .94+.51i .31+.058i .55+.14i .34+.3i .55+.86i .6+.14i
| .64+.34i .19+.19i .59+.75i .84+.03i .77+.98i .42+.038i .95+.02i
| .26+.14i .24+.72i .67+.44i .33+.4i .87+.67i .82+.92i .32+.099i
| .99+.11i .64+.82i .26+.42i .46+.63i .25+.42i .5+.24i .51+.93i
-----------------------------------------------------------------------
.49+.23i .016+.46i .58+.27i |
.8+i .41+.47i .96+.78i |
.71+.03i .15+.27i .86+.09i |
.58+.98i .68+.58i .45+.76i |
.63+.55i .59+.97i .95+.25i |
.63+.91i .94+.52i .17+.29i |
.47+.47i .23+.92i .7+.81i |
.75+.72i .44+.74i .23+.36i |
.1+.38i .62+.93i .39+.73i |
.096+.3i .51+.96i .43+.27i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .9+.62i .57+.9i |
| .63+.3i .22+.82i |
| .75+.27i .74+.82i |
| .23+.59i .94+.09i |
| .72+.51i .62+.37i |
| .53+.31i .43+.77i |
| .58+.69i .75+.59i |
| .019+.061i .8+.5i |
| .76+.04i .82+.18i |
| .32+.68i .12+.72i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .19-.43i 1.2+.98i |
| .52+1.2i .05+1.4i |
| .3-.39i .67-.12i |
| .57+.37i 1.1-.4i |
| -.17-.51i .3-.24i |
| .55-.53i .72-.33i |
| -.07-.67i -1.4+.07i |
| -.68+1.8i -.11-.18i |
| .44+.52i -.25+.25i |
| -.3-1.2i -1.3-.76i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.0299525296675e-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 = | .87 .91 .71 .4 .51 |
| .17 .79 .76 .15 .65 |
| .3 .37 .091 .6 .93 |
| .028 .73 .76 .65 .76 |
| .64 .95 .11 .7 .9 |
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 = | 1.5 -.48 .91 -.89 -.67 |
| -.98 .75 -2.1 .13 2.1 |
| .98 -.069 .51 .63 -1.6 |
| .38 -2.3 -.41 2 .2 |
| -.41 1.4 1.9 -1.1 -.6 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 4.44089209850063e-16
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 = | 1.5 -.48 .91 -.89 -.67 |
| -.98 .75 -2.1 .13 2.1 |
| .98 -.069 .51 .63 -1.6 |
| .38 -2.3 -.41 2 .2 |
| -.41 1.4 1.9 -1.1 -.6 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|