(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 = | .69+.78i .85+.39i .66+.29i .64+.01i .039+.37i .81+.21i .25+.7i
| .82+.75i .62+.77i .77+.19i .19+.12i .37+.4i .55+.79i .66+.09i
| .27+.5i .18+.61i .06+.97i .02+.87i .087+.44i .91+.87i .49+.48i
| .07+.64i .55+.44i .38+.45i .13+.5i .67+.87i .4+.82i .5+.75i
| .94+.68i .28+.71i .65+.8i .018+.29i .69+.52i .96+.88i .9+.63i
| .68+.7i .42+.15i .89+.41i .57+.48i .57+.26i .04+.77i .12+.78i
| .94+.45i .76+.2i .21+.92i .52+.69i .3+.48i .91+.99i .53+.92i
| .97+.41i .54+.41i .07+.75i .78+.79i .72+.84i .16+.91i .69+.02i
| .73+.37i .24+.1i .37+.88i .56+.13i .65+.39i 1+.31i .85+.38i
| .7+.93i .7+.87i .083+.23i .68+.32i .94+.68i .39+.67i .54+.84i
-----------------------------------------------------------------------
.26+.53i .52+.67i .39+.3i |
.54+.98i .17+.56i .24+.83i |
.6+.75i .99+.82i .71+.93i |
.15+.027i .89+.27i .01+.77i |
.76+.3i .74+.06i .67+.59i |
.28+.74i .4+.97i .098+.21i |
.95+.92i .75+.4i .098+.44i |
.41+.51i .09+.58i .96+.7i |
.68+.41i .89+.71i .16+.8i |
.28+.22i .83+.07i .35+.046i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .03+.63i .55+i |
| .16+.13i .62+.84i |
| .5+.26i .32+.73i |
| .13+.78i .29+.64i |
| .88 .91+.87i |
| .8+.86i .56+.6i |
| .71+.39i .3+.19i |
| .43+.62i .96+.63i |
| .91+.88i .85+.1i |
| .76+.82i .92+.37i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .41+.23i 1-.78i |
| -.43-.13i -.4+.33i |
| -.09-.28i -.094+.27i |
| .097+.092i -.34-.21i |
| .65+.78i .05-.62i |
| -.52+.23i .41-.17i |
| .08-.57i .37+.91i |
| .16-.3i -.39+.37i |
| .41+.13i .43-.57i |
| .18-.21i -.14+.86i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 4.57756679852224e-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 = | .21 .48 .53 .063 .86 |
| .28 .33 .018 .47 .74 |
| .93 .87 .61 .17 .92 |
| .69 .76 .53 .74 .63 |
| .24 .74 .88 .49 .62 |
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 = | 6.7 -5.3 -2.9 7.7 -6.5 |
| -18 12 10 -18 15 |
| 9.7 -7.2 -5.1 9.1 -6.5 |
| 2.6 -1.4 -2.6 4 -2.1 |
| 3.7 -.83 -1.6 2.2 -2.4 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 1.99840144432528e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 5.32907051820075e-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 = | 6.7 -5.3 -2.9 7.7 -6.5 |
| -18 12 10 -18 15 |
| 9.7 -7.2 -5.1 9.1 -6.5 |
| 2.6 -1.4 -2.6 4 -2.1 |
| 3.7 -.83 -1.6 2.2 -2.4 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|