(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 = | .77+.69i .77+.01i .93+.07i .01+.9i .1+.99i .27+.39i .24+i
| .12+.64i .69+.85i .057+.08i .45+.006i .55+.58i .98+.26i .72+.86i
| .31+.86i .025+.41i .69+.26i .62+.07i .26+.43i .49+.29i .13+.28i
| .88+.38i .52+.04i .8+.98i .51+.72i .66+.81i .66+.1i .018+.34i
| .09+.83i .16+.8i .82+.4i .41+.41i .74+.82i .62+.52i .8+.68i
| .28+.58i .37+.16i .67+.58i .04+.7i .4+.048i .69+.42i .68+.02i
| .26+.5i .45+.74i .52+.19i .39+.46i .66+.6i .41+.38i .33+.36i
| .74+.5i .86+.85i .3+.036i .7+.01i .42+.34i .059+.044i .7+.64i
| .93+.03i .19+.96i .1+.17i .12+.74i .81+.6i .68+.14i .89+.1i
| .02+.55i .21+.72i .47+.22i .63+.3i .07+.047i .97+.31i .38+.95i
-----------------------------------------------------------------------
.51+.12i .66+.36i .2+.2i |
.18+.44i .17+.25i .39+.45i |
.34+.009i .46+.49i .83+.5i |
.79+.78i .16+.032i .54+.16i |
.58+.05i .22+.92i .02+.97i |
.12+.76i .83+.11i .51+.5i |
.34+.75i .32+.96i .49+.97i |
.71+.49i .83+.78i .23+.68i |
.18+.069i .87+.23i .07+.97i |
.97+.62i .56+.4i .66+.83i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .25+.1i .96+.24i |
| .49+.97i .74+.51i |
| .11+.89i .21+.32i |
| .46+.04i .89+.72i |
| .53+.78i .02+.59i |
| .79+.92i .29+.48i |
| .77+.71i .11+.94i |
| .07+.75i .28+.79i |
| .86+.99i .69+.37i |
| .8+.8i .5+.62i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.8-7.5i -3.8+6.3i |
| -4-1.9i 2.7+3.4i |
| .14+3.6i 1.8-2.3i |
| -7.7-.18i 4.7+3.7i |
| 9.3+1.6i -5.7-6.5i |
| -11+3i 11+4.1i |
| .84-4.5i -3.6+3.2i |
| 4.3-2.7i -3.7-.07i |
| -2.7+11i 8.3-6.8i |
| 5.3-5.3i -6.6+1.3i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 4.92768959440774e-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 = | .35 .71 .41 .95 .87 |
| .19 .3 .34 .46 .59 |
| .88 .88 .61 .16 .86 |
| .033 .24 .42 .24 .91 |
| .44 .64 .04 .29 .39 |
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 = | -10 21 -2 -4.2 6 |
| 11 -22 2.8 3.4 -5.1 |
| 7.9 -13 3.4 1.2 -7.6 |
| -1.3 5.5 -1.1 -1.8 .89 |
| -5.7 9.6 -2 .29 4.4 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 1.77635683940025e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 1.77635683940025e-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 = | -10 21 -2 -4.2 6 |
| 11 -22 2.8 3.4 -5.1 |
| 7.9 -13 3.4 1.2 -7.6 |
| -1.3 5.5 -1.1 -1.8 .89 |
| -5.7 9.6 -2 .29 4.4 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|