(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 = | .51+.47i .1+.58i .46+.2i .26+.96i .17+.001i .7+.67i .75+.97i
| .3+.22i .63+.49i .2+.35i .99+.68i .61+.09i .4+.49i .55+.48i
| .54+.64i .39+.6i .69+.06i .91+.04i .84+.26i .69+.79i .068+.34i
| .55+.93i .34+.19i .44+.021i .43+.34i .89+.67i .8+.72i .9+.04i
| .68+.48i .13+.36i .39+.8i .033+.22i .5+.67i .064+.038i .92+.16i
| .79+.89i .54+.43i .85+.88i .022+.19i .35+.39i .54+.72i .69+.58i
| .8+.25i .21+.48i .66+.56i .52+.87i .22+.98i .24+.82i .73+.32i
| .66+.54i .54+.94i .67+.83i .18+.15i .43+.62i .12+.084i .83+.98i
| .74+.81i .93+.88i .39+.82i .82+.54i .92+.01i 1+.54i .72+.81i
| .82+.6i .74+.16i .87+.77i .32+.66i .54+.6i .5+.2i 1+.55i
-----------------------------------------------------------------------
.71+.55i .73+.31i .9+.41i |
.32+.12i .58+.43i .98+.77i |
.35+.94i .71+.68i .63+.08i |
.57+.92i .03+.74i .49+.71i |
.4+.63i .046+.11i .02+.65i |
.96+.06i .82+.18i .94+.91i |
1+.18i .52+.07i .47+.51i |
.94+.73i .91 .12+.076i |
.87+.42i .7+.21i .18+.95i |
.15+.72i .73+.68i .72+.3i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .83+.43i .02+.56i |
| .04+.7i .99+.43i |
| .81+.38i .11+.56i |
| .05+.55i .052+.34i |
| .25+.41i .49+.27i |
| .49+.011i .99+.93i |
| .24+.98i .14+.76i |
| .97+.94i .84+.67i |
| .096+.096i .32+.92i |
| .82+.72i .7+.05i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .73+.67i .06+.21i |
| -2-.59i .77-.76i |
| .83+.07i -.51+.47i |
| .33+1.6i -.6+.48i |
| .2+1.3i .28-.76i |
| -.79-1.6i -.26+.36i |
| 2.9-.87i .21+.22i |
| -.74+2i -.77+.04i |
| 1.1-2.9i .88+.64i |
| -1.7+.83i .87-.69i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.48952049194836e-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 = | .25 .57 .47 .069 .021 |
| .81 .054 .11 .29 .97 |
| .42 .39 .64 .68 .84 |
| .67 .67 .52 .56 .33 |
| .21 .78 .99 .83 1 |
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.1 .08 2.4 .13 -2.2 |
| -1.5 1.3 -7.1 2.2 4 |
| 3.7 -1.6 7.4 -3 -3.8 |
| -2.8 -1.1 .26 2.1 .16 |
| -.46 1.4 -2.5 -.52 2 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 8.88178419700125e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 1.76247905159244e-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.1 .08 2.4 .13 -2.2 |
| -1.5 1.3 -7.1 2.2 4 |
| 3.7 -1.6 7.4 -3 -3.8 |
| -2.8 -1.1 .26 2.1 .16 |
| -.46 1.4 -2.5 -.52 2 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|