(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 = | 2.2e-16 |
| -2.2e-16 |
| 0 |
3 1
o10 : Matrix RR <--- RR
53 53
|
i11 : norm oo
o11 = 2.22044604925031e-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 = | .066+.026i .03+.62i .08+.8i .12+.5i .65+.33i .6+.83i .13+.19i
| .61+.99i .23+.81i .4+.81i .53+.7i .82+.51i .62+.42i .97+.22i
| .26+.53i .54+.91i .75+.87i .77+.52i .31+.31i 1+.28i .71+.72i
| .42+.26i .99+.57i .85+.26i .56+.49i .67+.17i .63+.14i .08+.77i
| .19+.62i .95+.7i .8+.64i .3+.06i .04+.6i .19+.22i .001+.3i
| .22+.85i .88+.83i .53+.05i .92+.05i .98+.75i .26+.083i .33+.99i
| .99+.39i .17+.17i .55+.71i .36+.34i .92+.57i .32+.37i .05+.75i
| .007+.36i .05+.6i .98+.96i .84+.99i .24+.41i .82+.23i .54+.27i
| .025+.22i .46+.7i .99+.17i .28+.3i .41+.94i .54+.1i .42+.65i
| .41+.42i .24+.16i .64+.73i .21+.47i .63+.18i .073+.46i .73+.76i
-----------------------------------------------------------------------
.11+.26i .85+.28i .18+.27i |
.84+.65i .53+.04i .67+.04i |
.9+.46i .086+.31i .22+.71i |
.18+i .04+.81i .3+.75i |
.67+.62i .02+.66i .21+.88i |
.1+.57i .058+.2i .38+.54i |
.06+.94i .95+.89i .73+.31i |
.16+.018i .5+.9i .32+.94i |
.43+.95i .13+.25i .25+.78i |
1+.59i .48+.29i .61+.76i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .068+.3i .02+.81i |
| .03+.96i .76+.08i |
| .52+.91i .27+.77i |
| .69+.13i .98+.77i |
| .67+.91i .47+.34i |
| .13+.16i .28+.84i |
| .23+.95i .73+.28i |
| .85+.83i .63+.58i |
| .1+.1i .62+.78i |
| .83+.36i .57+.19i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | 2.2-1.1i -.87+.12i |
| .1-1.6i .47+.53i |
| .39+1.7i .46-.66i |
| -1.5-.86i -.079-.25i |
| -.77+1.4i .37+.067i |
| -.46+.64i -.048+.44i |
| .23-.54i .32+.34i |
| -.14+1.2i -.2-.72i |
| 2+.25i -.35-.38i |
| -1.6-2i .74+.71i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.96732021192296e-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 = | .64 .7 .84 .85 .073 |
| .21 .18 .79 .68 .95 |
| .57 .45 .77 .45 .83 |
| .57 .53 .053 .76 1 |
| .017 .82 .8 .27 .45 |
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 = | .29 -1.2 2 -.067 -1 |
| -.006 -.97 -.29 .62 1.2 |
| .17 .46 .65 -1 .045 |
| .86 1.2 -1.9 .51 -.28 |
| -.83 .24 .45 .38 .17 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 2.22044604925031e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 7.49400541621981e-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 = | .29 -1.2 2 -.067 -1 |
| -.006 -.97 -.29 .62 1.2 |
| .17 .46 .65 -1 .045 |
| .86 1.2 -1.9 .51 -.28 |
| -.83 .24 .45 .38 .17 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|