(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 = | .49+.045i .61+i .65+.58i .87+.27i .01+.59i .88+.91i .87+.93i
| .54+.29i .19+.21i .75+.65i .38+.2i .49+.95i .062+.24i .04+.75i
| .14+.63i .94+.61i .7+.23i .47+.29i .8+.72i .53+.99i .34+.096i
| .66+.14i .92+.33i .33+.45i .77+.59i .95+.5i .64+.16i .04+.67i
| .047+.23i .39+.48i .83+.14i .39+.98i .43+.52i .81+.84i .78+.28i
| .24+.62i .45+.28i .7+.51i .3+.41i .26+.96i .74+.72i .96+.34i
| .47+.31i .67+.22i .57+.63i .55+.74i .47+.95i .17+.28i .53+.02i
| .05+.99i .27+.99i .91+.16i .092+.13i .09+.27i .35+.16i .98+.47i
| .23+.25i .026+.052i .02+.98i .69+.15i .66+.15i .18+.51i .59+.29i
| .21+.1i .87+.74i .67+.42i .17+.36i .61+.12i .08+.78i .91+.82i
-----------------------------------------------------------------------
.88+.42i .75+.43i .53+.34i |
.17+.51i .54+.56i .7+.05i |
.75+.25i .32+.35i .21+.95i |
.14+.56i .09+.92i .53+.58i |
.24+.94i .09+.72i .71+.25i |
.66+.16i .07+.94i .56+.25i |
.3+.65i .13+.25i .86+.68i |
.05+.82i .14+.71i .24+.31i |
.94+.39i .63+.76i .57+.59i |
.17+.92i .98+.14i .49+.74i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .83+.94i .2+.72i |
| .12+.84i .51+.22i |
| .87+.55i .29+.53i |
| .49+.11i .33+.66i |
| .76+.86i .19+.78i |
| .65i .03+.57i |
| .99+.83i .55+.61i |
| .28+.66i .73+.59i |
| .05+.78i .93+.34i |
| .12+.39i .29+.62i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.29+1.3i .48+.11i |
| -.93-1.3i -.52-.03i |
| .69+1.2i -.041-.4i |
| -.11-.29i -.3+1.3i |
| .28-.44i .3-.15i |
| -.02+1.1i .76+.32i |
| -.29+.011i -.09+.65i |
| 1.2+.28i .24-1.4i |
| -.48+.15i -.11+.18i |
| 1.1-1.4i .17-.43i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.20088981274602e-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 = | .9 .6 .88 .84 .13 |
| .75 .39 .97 .63 .044 |
| .036 .54 .93 .12 .85 |
| .96 .32 .4 .13 .068 |
| .31 .38 .61 .45 .41 |
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.6 .29 -1 1.6 2.3 |
| 6.9 -3.8 3.1 -1 -8.1 |
| -1.2 2.4 .67 -.41 -1.2 |
| -.37 -.12 -1.7 -.69 3.7 |
| -3 -.22 -1.3 1.1 5.9 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 1.33226762955019e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 2.66453525910038e-15
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.6 .29 -1 1.6 2.3 |
| 6.9 -3.8 3.1 -1 -8.1 |
| -1.2 2.4 .67 -.41 -1.2 |
| -.37 -.12 -1.7 -.69 3.7 |
| -3 -.22 -1.3 1.1 5.9 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|