(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 = | 1+.26i .41+.26i .21+.25i .38+.34i .79 .36+.99i .26+.92i
| .88+.95i .58+.57i .48+.15i .64+.03i .08+.94i .1+.83i .5+.36i
| .44+.91i .095+.21i .93+.25i .37+.56i .035+.18i .28+.73i .2+.11i
| .27+.52i .91+.45i .47+.56i .81+.96i .68+.84i .81+.73i .11+.81i
| .17+.46i .3+.23i .016+.37i 1+.44i .21+.79i .23+.84i .35+.24i
| .82+.14i .84+.45i .98+.59i .1+.55i .15+.13i .73+.99i .37+.16i
| .74+.39i .52+.34i .49+.87i .87+.34i .28+.44i .29+.22i .81+.34i
| .81+.54i .15+.7i .32+.25i .33+.68i .19+.46i .65+.66i .81+.07i
| .81+.59i .69+.86i .24+.13i .59+.46i .9+.28i .12+.88i .47+.12i
| .49+.33i .4+.26i .77+.03i .33+.95i .86+.05i .89+.9i .34+.84i
-----------------------------------------------------------------------
.13+.038i .69+.35i .62+.51i |
.26+.21i .042+.1i .32+.4i |
.55+.38i .06+.75i .66+.66i |
.51+.96i .28+.053i .85+.45i |
.35+.48i .53+.38i .47+.15i |
.71+.05i .9+.97i .53i |
.45+.52i .093+.34i .83+.95i |
.96+.32i .38+.8i .92+.44i |
.06+.63i .95+.07i .42+.79i |
.49+.58i .41+.47i .88+.03i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .28+.056i .56+.02i |
| .32+.18i .77+.55i |
| .68+.63i .86+.87i |
| .27+.85i .84+.98i |
| .57+.11i .98+.22i |
| .24+.29i .19+.081i |
| .6+.47i .82+.96i |
| .49+.11i .24+.44i |
| .24+.82i .72+.07i |
| .25+.71i .81+.61i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .58+.12i -.33+.15i |
| -.28+.44i .34-.42i |
| .043+.18i .3+.65i |
| .63-.14i 1.3+.64i |
| -.25+.18i .2+.18i |
| -.32-.073i .16-.07i |
| -.26+.093i -.27-.088i |
| .57-.43i -.68-.23i |
| .012+.016i -.46-1.1i |
| -.066-.099i .28-.067i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 8.48363141713211e-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 = | .19 .045 .048 .25 .047 |
| .098 .29 .89 .18 .081 |
| .52 .21 .97 .72 .86 |
| .052 .096 .096 .43 .16 |
| .88 .00011 .85 .32 .56 |
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 = | 8.8 -.34 1.8 -7 -1.4 |
| 28 .23 10 -26 -11 |
| -9 1.2 -3.2 7.8 3.3 |
| -6.9 .26 -3.4 9.8 2.9 |
| 3.7 -1.4 4 -6.4 -2.6 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 1.55431223447522e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 4.88498130835069e-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 = | 8.8 -.34 1.8 -7 -1.4 |
| 28 .23 10 -26 -11 |
| -9 1.2 -3.2 7.8 3.3 |
| -6.9 .26 -3.4 9.8 2.9 |
| 3.7 -1.4 4 -6.4 -2.6 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|