(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+.96i .36+.53i .63+.21i .45+.27i .69+.58i .84+.24i .73+.74i
| .55+.39i .6+.96i .66+.99i .3+.067i .14+.54i .47+.19i .09+.56i
| .11+.55i .34+.59i .18+.95i .23+.29i .12+.18i .32+.76i .56+.84i
| .77+.62i .16+.5i .36+.28i .39+.27i .44+.96i .95+.54i .12+.7i
| .64+.96i .35+.49i .58+.17i .16+.72i .55+.21i .9+.79i .41+.67i
| .02+.89i .9+.98i .43+.97i .59+.25i .34+.95i .72+.94i .43+.66i
| .61+.8i .65+.61i .16+.85i .46+.68i .69+.4i .03+.56i .82+.45i
| .4+.72i .71+.89i .14+.83i .07+.94i .071+.25i .81+.06i .47+.73i
| .4+.46i .97+.76i .88+.42i .49+.75i .03+.7i .73+.89i .99+.62i
| .44+.56i .59+.61i .31+.69i .062+.2i .92+.71i .87+.52i .44+.79i
-----------------------------------------------------------------------
.3+.22i .66+.42i .1+.98i |
.39+.47i .2+.74i .24+.32i |
.1+.98i .48+.38i .26+.41i |
.92+.35i .18+.6i .64+.83i |
.37+.88i .27+.053i .56+.12i |
.96+.57i .48+.41i .12+.27i |
.67+.72i .63+.95i .6+.14i |
.32+.23i .39+.12i .46+.7i |
.35+.89i .19+.48i .53+.06i |
.7+.04i .64+.58i .76+.04i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .25+.87i .36+.57i |
| .15+.77i .082+.32i |
| .07+.79i .78+.24i |
| .28+.74i .91+.29i |
| .41+.68i .52+.57i |
| .45+.028i .2+.73i |
| .76+.27i .3+.6i |
| .14+.56i .55+.52i |
| .43+.51i .68+.15i |
| .51+.83i .07+.18i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | 1.3+1.1i -.5+1.6i |
| -.49-.61i .41+.4i |
| -.23-.27i .17-.48i |
| -.82-.5i .54-.53i |
| 1.2-2i 1.3+1.2i |
| -.87+.51i .22-.86i |
| .85+.16i .025-.036i |
| .27-.92i .43-.26i |
| .37+1.8i -1.4+.15i |
| -1.2+.26i .26-1.7i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 9.42055475210265e-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 .062 .49 .97 .77 |
| .12 .6 .94 .6 .4 |
| .19 .5 .15 .61 .052 |
| .56 .41 .99 .93 .031 |
| .93 .59 .42 .27 .87 |
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 = | -.25 -1.2 -.22 .97 .76 |
| -.77 .86 1.4 -.74 .23 |
| -.22 .83 -1.3 .57 -.13 |
| .71 -.56 .89 .24 -.43 |
| .68 .47 -.36 -.89 .38 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 2.4980018054066e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 6.66133814775094e-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 = | -.25 -1.2 -.22 .97 .76 |
| -.77 .86 1.4 -.74 .23 |
| -.22 .83 -1.3 .57 -.13 |
| .71 -.56 .89 .24 -.43 |
| .68 .47 -.36 -.89 .38 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|