(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 = | .24+.37i .93+.75i .11+.37i .5+.41i .13+.23i .88+.86i .24+.087i
| .82+.6i .26+.067i .38+.97i .85+.74i 1+.83i .02+.91i .2+.23i
| .9+.74i .067+.44i .9+.07i .27+.67i .28+.68i .49+.13i .27+.092i
| .83+.06i .07+.53i .17+.29i .92+.22i .39+.91i .2+.045i .73+.45i
| .72+.66i .69+.12i .83 .38+.045i .56+.61i .83+.83i .29+i
| .47+.1i .49+.93i .43+.32i .28+.2i .071+.4i .18+.76i .48+.25i
| .06+.94i .8+.88i .75+.08i .8+.19i .92+.64i .76+i .57+.57i
| .54+.71i .93+.78i .99+.53i .56+.77i .34+.31i .43+.99i .01+.55i
| .25+.027i .05+.2i .33+.51i .91+.4i .36+.36i .37+.79i .55+.47i
| .98+.83i .98+.94i .34+.83i .8+.21i .1+.73i .74+.17i .8
-----------------------------------------------------------------------
.64+.91i .94+.63i .19+.15i |
.71+.82i .97+.97i 1+.79i |
.044+.018i .76+.63i .43+.56i |
.55+.2i .44+.51i .38+.92i |
.92+.43i .6+.09i .97+.21i |
.78+.12i .75+.2i .47+.82i |
.39+.89i .57+.36i .19+.82i |
.26+.81i .3+.58i .25+.93i |
.7+.25i .36+.6i .2+.91i |
.28+.004i .68+.18i .12+.55i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .51+.86i .36+.38i |
| .04+.98i .15+.82i |
| .013+.4i .61+.04i |
| .43+.35i .6+.59i |
| .19+.32i .42+.68i |
| .26+.24i .36+.42i |
| .42+.15i .81+.2i |
| .61+.89i .96+.95i |
| .11+.28i .72+.97i |
| .25+.54i .01+.54i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.73-.06i -.95+.65i |
| .13-.76i -.13-.3i |
| 1.4+.2i 1.3-.36i |
| 1-.71i -.07-.7i |
| -.43-.35i -.046+.35i |
| -.74+1.1i .43+1.2i |
| .21+.91i .83-.22i |
| 1.8-.78i .18-.73i |
| -1.1+.05i -.31-.11i |
| .2+1.1i .64-.08i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 5.55111512312578e-16
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 = | .53 .34 .36 .56 .12 |
| .97 .26 .14 .16 .39 |
| .73 .19 .54 .75 .64 |
| .023 .51 .43 .69 .7 |
| .78 .081 .63 .55 .41 |
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 = | .33 .74 .4 -.71 -.21 |
| 1.2 1.2 -3 1.6 .52 |
| -.54 -.31 -4 1.3 4.5 |
| 1.5 -1.3 3.9 -1.3 -3 |
| -2.1 .64 .83 .79 -.21 |
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 = 7.7715611723761e-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 = | .33 .74 .4 -.71 -.21 |
| 1.2 1.2 -3 1.6 .52 |
| -.54 -.31 -4 1.3 4.5 |
| 1.5 -1.3 3.9 -1.3 -3 |
| -2.1 .64 .83 .79 -.21 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|