(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 = | .45+.92i .74+.26i .88+.53i .49+.96i .97+.38i .53+.69i .03+.33i
| .28+.22i .51+.59i .46+.85i .42+.37i .19+.049i .39+.59i .51+.79i
| .78+.03i .65+.43i .18+.84i .31+.17i .25+.26i .16+.61i .56+.74i
| .63+i .85 .076+.45i .56+.33i .89+.25i .21+.89i .89+.47i
| .86+.3i .26+.34i .7+.39i .77+.08i .75+.06i .68+.51i .97+.07i
| .69+.5i .26+.89i .81+.72i .91+.3i .28+.51i .52+.46i .68+.99i
| .13+.32i .94+.64i .64+.68i .22+.36i .77+.05i .89+.23i .6+.2i
| .82+.53i .41+.16i .74+.22i .86+.04i .39+.86i .04+.91i .53+.76i
| .68+.73i .91+.33i .47+.21i .86+.12i .78+.24i .46+.93i .36+.56i
| .21+.45i .47+.12i .55+.42i .86+.02i .7+.79i .43+.28i .72+.36i
-----------------------------------------------------------------------
.44+.87i .45+.59i .53+.16i |
.34+.54i .08+.24i .61+.21i |
.13+.51i .45+.69i .77+.3i |
.73+.08i .15+.43i .56+.18i |
.1+.79i .67+.91i .48+.79i |
.31+.79i .78+.73i .28+.19i |
.23+.61i .78+.6i .17+.15i |
.89+.25i .86+.13i .22+.52i |
.91+.28i .08+.49i .58+.49i |
.62+.47i .098+.15i .28+.13i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .11+.52i .62+.72i |
| .93+.91i .35+.22i |
| .84+.64i .94+.61i |
| .13+.58i .76+.89i |
| .43+.8i .95+.07i |
| .009+.35i .8+.55i |
| .65+.01i .08+.88i |
| .024+.33i .95+.32i |
| .98+.73i .02+.55i |
| .19+.75i .34+.091i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.23+2i .73-.28i |
| -.08-.55i .61i |
| .52-.68i .19-.13i |
| -.05-1.5i .11-.033i |
| .072+.05i .1+.078i |
| -.15+.79i -.53-.05i |
| .017+.36i .45-.23i |
| 2.2+1.7i -.83-.39i |
| -.76-1.5i .48+.53i |
| .34-1.1i .24+.25i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.09344286978131e-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 = | .85 .55 .44 .89 .95 |
| .38 .79 .7 .1 .47 |
| .16 .67 .55 .55 .054 |
| .57 .75 .23 .77 .33 |
| .51 .94 .93 .18 .83 |
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 = | 3.3 12 -.88 -2.4 -9.7 |
| -2.7 -4.3 -.96 3.4 4.2 |
| 2.3 5.5 2 -3.8 -4.4 |
| .22 -3 1.4 .14 1.3 |
| -1.6 -8.3 -.85 1.8 7 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 1.77635683940025e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 2.22044604925031e-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 = | 3.3 12 -.88 -2.4 -9.7 |
| -2.7 -4.3 -.96 3.4 4.2 |
| 2.3 5.5 2 -3.8 -4.4 |
| .22 -3 1.4 .14 1.3 |
| -1.6 -8.3 -.85 1.8 7 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|