(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 |
| 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 = | .3+.65i .54+.65i .28+.37i .78+.72i .36+.79i .73+.51i .49+.99i
| .02+.85i .33+.76i .4+.71i .44+.13i .82+.84i .26+.12i .5+.008i
| .85+.55i .93+.7i .95+.58i .56+.27i .54+.14i .9+.35i .66+.4i
| .64+.34i .63+.89i .95+.86i .032+.24i .78+.92i .36+.57i .95+.39i
| .53+.49i .84+.97i .48+.19i .9+.27i .99+.55i .22+.72i .62+.14i
| .84+.97i .063+.18i .51+.57i .81+.89i .18+.71i .3+.11i .47+.16i
| .39+.59i .96+.91i .13+.79i .76+.86i .95+.34i .71+.28i .6+.61i
| .076+.36i .13+.11i .42+.66i .2+.86i .5+.17i .91+.6i .79+.26i
| .79+.49i .81+.37i .63+.73i .66+.06i .85+.18i .18+.35i .39+.44i
| .21+.72i .65+.89i .41+.2i .52+.63i .99+.61i .63+.38i .24+.71i
-----------------------------------------------------------------------
.08+.68i .73+.2i .84+.48i |
.17+.24i .54+.74i .35+.73i |
.53+.45i .55+.42i .12+.46i |
.5+.92i .61+.45i .96+.91i |
.44+.34i .19+.96i .67+.51i |
.78+.56i .2+.49i .66+.41i |
.7+.09i .53+.27i .59+.16i |
.94+.15i .85+.74i .73+.05i |
.97+.6i .041+.45i .31+.83i |
.81+.95i .43+.081i .65+.34i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .28+.27i .37+.88i |
| .31+.75i .32+.27i |
| .85+.01i 1+.58i |
| .81+.12i .15+.73i |
| .007+.44i .51+.05i |
| .8+.81i .91+.35i |
| .84+.32i .33+.67i |
| .98+.05i .57+.15i |
| .6+.08i .68+.47i |
| .53+.3i .81+.3i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .48+.38i .52+.79i |
| .2-.088i -1.4 |
| .52-.54i .74-.21i |
| -.38-.34i .18-.5i |
| .1i 1.6+1.2i |
| -1+1.3i 2.4+2.3i |
| -.25-.9i -.74-.55i |
| .31-.57i -1.4-i |
| 1.1-1.2i -2.1-1.8i |
| -.27+1.2i 1-.11i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 7.7715611723761e-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 = | .81 .33 .26 .95 .069 |
| .25 .56 .77 .14 .2 |
| .11 .84 .69 .35 .04 |
| .6 .12 .016 .59 .31 |
| .33 .54 .4 .54 .025 |
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 = | 64 -21 100 .67 -170 |
| 44 -18 75 1.9 -120 |
| -34 15 -58 -2.2 96 |
| -57 19 -91 -.84 160 |
| -32 11 -47 2.9 81 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 2.8421709430404e-14
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 8.88178419700125e-15
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 = | 64 -21 100 .67 -170 |
| 44 -18 75 1.9 -120 |
| -34 15 -58 -2.2 96 |
| -57 19 -91 -.84 160 |
| -32 11 -47 2.9 81 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|