(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 = | .83+.88i .1+.81i .38+.44i .25+.12i .92+.29i .82+.65i .17+.61i
| .24+.42i .3+.23i .33+.14i .35+.003i .79+.92i .9+.36i .45+.77i
| .68+.26i .52+.04i .44+.68i .12+.24i .47+.8i .36+.53i .75+.42i
| .96+.69i .3+.43i .8+.7i .38+.54i .5+.02i .02+.21i .54+.88i
| .61+.24i .48+.017i .98+.48i .24+.46i .61+.53i .7+.32i .64+.99i
| .97+.72i .1+.005i .83+.61i .19+.95i .15+.77i .37+.74i .025+.28i
| .04+.73i .43+.35i .46+.72i .65+.63i .75+.84i .99+.76i .11+.027i
| .17+.34i .51+.87i .46+.57i .76+.72i .33+.17i .36+.28i .55+.12i
| .31+.28i .24+.61i .92+.24i .95+.85i .38+.2i 1+.59i .15+.24i
| .98+.54i .09+.98i .15+.34i .022+.49i .24+.9i .61+.29i .1+.68i
-----------------------------------------------------------------------
.019+.25i .48+.72i .95+.96i |
.18+.89i .76+.59i .82+.45i |
.42+.27i .1+.77i .88+.76i |
.18+.1i .05+.88i .055+.035i |
.67+.27i .84+.22i .36+.25i |
.07+.54i .93+.64i .52+.23i |
.95+.49i .67+.77i .61+.57i |
.93+.99i .88+.28i .26+.57i |
.65+.86i .82+.28i .31+.62i |
.77+.51i .86+.64i .25+.38i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .74+.07i .11+.93i |
| .57+.76i .99+.03i |
| .82+i .69+.76i |
| .38+.73i .28+.4i |
| .89+.77i .75+.72i |
| .95+.05i .56+.11i |
| .52+.22i .23+.54i |
| .4+.36i .74+.5i |
| .93+.07i .31+.26i |
| .53+.33i .16+.69i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .027-.071i -.6-.25i |
| 1.1+.72i .15-1.9i |
| 1.3+3i 2.6-1.7i |
| -1.9-1.5i -.45+1.5i |
| 1.6+.45i -.58-2i |
| -1.5+.47i .71+1.3i |
| -1.4-.03i 1.1+1.5i |
| 1.2-.7i -1.6-.22i |
| -.24-i -.17+i |
| .4-1.5i -.19+.67i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.22628141165784e-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 = | .58 .13 .25 .34 .88 |
| .9 .0045 .43 .12 .11 |
| .47 .31 .84 .8 .37 |
| .72 .14 .81 .034 .88 |
| .27 .19 .67 .67 .93 |
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 = | .99 .79 .24 -.22 -.92 |
| 4.1 -4.8 5.1 2.2 -7.4 |
| -2.2 .51 -.31 .85 1.4 |
| -.1 1 -.2 -1.7 1.7 |
| .57 -.37 -.73 .25 .64 |
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 = 2.22044604925031e-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 = | .99 .79 .24 -.22 -.92 |
| 4.1 -4.8 5.1 2.2 -7.4 |
| -2.2 .51 -.31 .85 1.4 |
| -.1 1 -.2 -1.7 1.7 |
| .57 -.37 -.73 .25 .64 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|