(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 = | .39+.95i .7+.05i .08+.72i .14+.38i .93+.22i .13+.44i .23+.77i
| .13+.43i .72+.75i .03+.77i .07+.25i .72+.64i .53+.96i .07+.73i
| .081+.33i .9+.47i .98+.28i .1+.88i .96+.91i .41+.24i .4+.32i
| .051+.12i .5+.66i .81+.14i .033+.1i .29+.42i .27+.37i .09+.55i
| .19+.3i .58+.72i .61+.29i .036+.048i .62+.03i .04+.52i .24+.5i
| .99+.13i .4+.81i .78+.58i .53+.63i .86+.95i .27+.37i .5+.41i
| .08+.98i .6+.27i .74+.44i .56+.34i .35+.65i .93+.13i .17+.98i
| .53+.91i .35+.74i .97+.8i .98+.15i .33+.33i .39+.83i .64+.96i
| .67+.91i .94+.73i .04+.58i .9+.29i .79+.13i .3+.89i .18+.54i
| .52+.92i .61+.77i .23+.73i .7+.37i .14+.99i .17+.3i .67+.82i
-----------------------------------------------------------------------
.25+.86i .23+.37i .96+.34i |
.1+.065i .33+.3i .81+.26i |
.86+.99i .88+.96i .71+.03i |
.45+.21i .83+.03i .18+.79i |
.82+.7i .49+.73i .36+.96i |
.63+.12i .46+.34i .0072+.0039i |
.77+.07i .16+.1i .07+.99i |
.88+.63i .02+.74i .09+.91i |
.13+.2i .19+.51i .75+.81i |
.11+.93i .16+.56i .41+.17i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .025+.11i .98+.71i |
| .29+.039i .89+.19i |
| .41+.64i .94+.05i |
| .47+.52i .22+.5i |
| .74+.15i .05+.73i |
| .047+.38i .71+.81i |
| .33+.012i .14+.45i |
| .21+.072i .15+.36i |
| .9+.29i .96+.34i |
| .13+.75i .52+.52i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -1.4-1.4i -.58+2.4i |
| 1-4.5i -3.3+1.5i |
| 2.6-2.7i -3.1-1.6i |
| 1.4+1.9i 1.4-2.3i |
| -.09+.87i .75-.33i |
| -1.3+3.3i 2.7-.42i |
| -3.8+3i 3.6+1.9i |
| 2.3-.2i -.6-1.4i |
| -2.1+2.6i 2.3+.89i |
| 3.1+1.6i .99-3.2i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 3.21964677141295e-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 = | .47 .46 .86 .71 .085 |
| .15 .54 .63 .59 .03 |
| .56 .061 .12 .69 .44 |
| .86 .68 .7 .65 .5 |
| .65 .45 .23 .32 .86 |
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 = | -.76 -1.8 .22 3 -1.7 |
| -3.7 2.6 -.45 2.6 -.99 |
| 4.1 -1.7 -1.2 -2.4 1.6 |
| -.86 1.6 1.7 -.49 -.53 |
| 1.7 -.16 -.21 -2.8 2.7 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 6.66133814775094e-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 = | -.76 -1.8 .22 3 -1.7 |
| -3.7 2.6 -.45 2.6 -.99 |
| 4.1 -1.7 -1.2 -2.4 1.6 |
| -.86 1.6 1.7 -.49 -.53 |
| 1.7 -.16 -.21 -2.8 2.7 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|