(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 = | .66+.77i .68+.64i .68+.74i .45+.35i .095+.49i .6+.45i .43+.82i
| .35+.4i .32+.3i .6+.47i .16+.093i .63+.1i .73+.34i .85+.56i
| .2+.61i .24+.63i .07+.66i .13+.97i .77+.58i .44+.19i .96+.61i
| .33+.86i .091+.32i .04+.62i .49+.28i .25+.67i .32+.77i .48+.27i
| .77+i .21+.018i .25+.31i .53+.99i .89+.52i .8+.26i .83+.26i
| .56+.11i .34+.23i .37+.19i .89+.44i .76+.77i .42+.21i .59+.64i
| .52+.57i .23+.41i .45+.16i .31+.87i .2+.28i .87+.4i .15+.88i
| .89+.82i .69+.13i .36+.21i .18+.24i .53+.62i .74+.57i .083+.26i
| .66+.99i .39+.57i .97+.4i .63+.48i .078+.25i .67+.02i .097+.091i
| .2+.24i .83+.16i .38+.58i .63+.18i .82+.96i .77+.42i .78+.57i
-----------------------------------------------------------------------
.28+.36i .63+.99i .06+.9i |
.85+.37i .22+.87i .52+.71i |
.49+.57i .13+.28i .4+.62i |
.24+.26i .51+.46i .72+.89i |
.61+.49i .1+.45i .65+.31i |
.18+.61i .95+.34i .87+.09i |
.87+.06i .4+.62i .01+.79i |
.56+.92i .32+.055i .04+.7i |
.6+.73i .11+.44i .93+.66i |
.2+.48i .62+.19i .6+.38i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .41+.57i .05+.86i |
| .61+.61i .97+.73i |
| .67+.49i .79+.29i |
| .5+.15i .36+.42i |
| .41+.47i .4+.046i |
| .56+.33i .18+.28i |
| .67+.32i .94+.39i |
| .2+.064i .19+.21i |
| .12+.5i .09+.99i |
| .63+.56i .08+.54i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.39-.094i -.098-.065i |
| -.52-.59i -.78-1.5i |
| .85+.34i 1.5+1.7i |
| -.048+.11i -.62+.21i |
| 1.2-1.1i 1.9-i |
| -.49+.26i -.74-.47i |
| -.14+.6i .1+.46i |
| .51+.88i .2+1.4i |
| .4-.2i -.3-.035i |
| -.53-.41i -.27-.8i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.00074151062168e-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 = | .18 .18 .67 .9 .23 |
| .83 .93 .017 .45 .74 |
| .64 .8 .56 .0043 .34 |
| .37 .01 .093 .13 .38 |
| .88 .87 .038 .087 .22 |
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 = | .22 -1.4 -.69 2 2.1 |
| -.18 1.1 .57 -2.2 -.46 |
| .38 -.8 1.3 .39 -.44 |
| .98 .3 -1.1 -.44 .54 |
| -.63 1.4 .72 .79 -2.1 |
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 = 4.44089209850063e-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 = | .22 -1.4 -.69 2 2.1 |
| -.18 1.1 .57 -2.2 -.46 |
| .38 -.8 1.3 .39 -.44 |
| .98 .3 -1.1 -.44 .54 |
| -.63 1.4 .72 .79 -2.1 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|