(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 = | .76+.22i .58+.94i .48+.21i 1+.83i .28+.48i .58+.21i .9+.9i
| .36+.63i .6+.28i .75+.8i .86+.18i .64+.53i .6+.65i .84+.72i
| .74+.87i .28+.76i .6+.22i .52+.52i .83+.09i .09+.57i .78+.73i
| .37+.92i .66+.94i .2+.57i .67+.31i .4+.74i .47+.93i .39+.61i
| .18+.007i .9+.31i .91+.69i .98+.67i .92+.94i .56+.83i .22+.24i
| 1+.79i .93+.07i .12+.92i .59+.01i .9+.95i .58+.04i .46+.079i
| .2+.1i .65+.08i .62+.14i .83+.48i .89+.7i .23+.66i .17+.28i
| .73+.05i .74+.46i .56+.79i .08+.82i .56+.03i .72+.86i .77+.54i
| .17+.24i .24+.35i .27+.72i .18+.28i .75+.3i .96+.26i .81+.99i
| .69+.46i .37+.94i .1+.67i .74+.84i .66+.33i .95+.76i .33+.23i
-----------------------------------------------------------------------
.63+.75i .02+.91i .019+.33i |
.14+.55i .34+.53i .99+i |
.82+.12i .75+.16i .51+.33i |
.88+.23i .32+.062i .36+.74i |
.13+.13i .62+.36i .92+.59i |
.52+.27i .23+.67i .97+.48i |
.02+.0082i .49+.62i .74+.35i |
.79+.79i .23+.51i .44+.35i |
.98+.45i .48+.45i .6+.4i |
.94+.83i .38+.94i .35+.78i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .7+.84i .13+.26i |
| .42+.23i .48+.69i |
| .47+.6i .34+.88i |
| .21+.59i .47+.52i |
| .1+.84i .72+.56i |
| .15+.63i .02+.89i |
| .79+.85i .86+.89i |
| .6+.5i .51+.07i |
| .63+.57i .08+.97i |
| .28+.12i .85+.16i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.7-.17i -.86-.42i |
| .11+.19i -.24-1.2i |
| -.3-.57i .43-1.4i |
| .76+.49i .63+1.3i |
| .28+.79i .11+i |
| -.29-1.1i .32-1.8i |
| .71-.26i .42+.73i |
| .28+.89i -.47+1.4i |
| -.7-1.4i -.37-2i |
| -.11+1.3i -.2+2.1i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.11022302462516e-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 .24 .14 .12 .17 |
| .076 .51 .1 .64 .5 |
| .42 .97 .77 .051 .25 |
| .17 1 .89 .88 .032 |
| .91 .59 .44 .3 .99 |
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 = | 4.2 -.69 -.62 .062 -.22 |
| 2.8 1.9 1.7 -1.2 -1.8 |
| -4.7 -2.1 -.47 1.6 1.9 |
| .86 .16 -1.3 .95 .072 |
| -3.7 .41 .17 -.3 1.4 |
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 = 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 = | 4.2 -.69 -.62 .062 -.22 |
| 2.8 1.9 1.7 -1.2 -1.8 |
| -4.7 -2.1 -.47 1.6 1.9 |
| .86 .16 -1.3 .95 .072 |
| -3.7 .41 .17 -.3 1.4 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|