(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 = | .34+.11i .99+.79i .97+.28i .74+.49i .14+.26i .43+.97i .86+.61i
| .09+.93i .53+.81i .25+.83i .05+.64i .46+.22i .35+.62i .23+.55i
| .42+.68i .21+.02i .31+.84i .66+.57i .87+.26i .13+.7i .5+.44i
| .045+.33i .78+.9i .19+.81i .17+.84i .12+.44i .8+.81i .45+.55i
| .94+.63i .16+.57i .93+.63i .16+.7i .046+.15i .3+.76i .57+.47i
| .5+.66i .06+.78i .13+.41i .17+.14i .046+.22i .73+.12i .81+.5i
| .87+.19i .93+.24i .71+.66i .47+.76i .23+.16i .95+.96i .72+.04i
| .77+.26i .47+.61i .23+.82i .82+.67i .74+.69i .28+.92i .6+.44i
| .95+.17i .3+.005i .85+.22i .71+.47i .73+.97i .36+.029i .59+.29i
| .86+.13i .72+.15i .17+.94i .41+.79i .91+.68i .42+.21i .55+.07i
-----------------------------------------------------------------------
.26+.58i .35+.068i .37+.21i |
.52+.75i .57+.26i .44+.79i |
.1+.027i .76+.34i .07+.67i |
.79+.91i .58+.22i .94+.63i |
.69+.15i .81+.62i .63+.29i |
.89+.6i .47+.55i .48+.47i |
.93+.01i .06+.86i .85+.85i |
.037+.18i .14+.7i .75+.8i |
.6+.73i .55+.86i .52+.98i |
.61+.11i .76+.29i .04+.61i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .1+.61i .88+.01i |
| .61+.65i .27+.67i |
| .76+.14i .94+.14i |
| .78+.84i .95+.72i |
| .71+.2i .95+.15i |
| .71+.66i .4+.8i |
| .96+.42i .16+.96i |
| .23+.55i .99+.1i |
| .23+.48i .15+.11i |
| .071+.21i .75+.87i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -7.6+3i 7.2+5.2i |
| -3.2+6.5i 8.3+.3i |
| 8.5+6.6i 1.3-13i |
| -35-12i 9.4+42i |
| 18-.8i -13-18i |
| 9.6+6.8i .4-14i |
| 27-15i -30-17i |
| -17+7.7i 17+13i |
| -7.2+2.3i 7.8+6.5i |
| 9.4-1.4i -5.8-8.4i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.65423230669148e-14
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 = | .57 .45 .85 .37 .99 |
| .32 .44 .84 .66 .0047 |
| .45 .049 .087 .081 .51 |
| .28 .71 .28 .52 .87 |
| .56 .29 .95 .76 .72 |
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 = | -.39 1.7 3.4 -.49 -1.3 |
| .82 1.6 .28 .9 -2.4 |
| 1.6 .078 -1.5 -.95 -.044 |
| -2.4 -.43 .019 .85 2.3 |
| .38 -1.6 -.86 .38 1 |
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 = 7.7715611723761e-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 = | -.39 1.7 3.4 -.49 -1.3 |
| .82 1.6 .28 .9 -2.4 |
| 1.6 .078 -1.5 -.95 -.044 |
| -2.4 -.43 .019 .85 2.3 |
| .38 -1.6 -.86 .38 1 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|