(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 = | .48+.054i .66+.32i .78+.79i .28+.2i .64+.66i .64+.9i .15+.6i
| .83+.48i .74+.33i .13+.056i .93+.15i .057+.45i .79+.22i .46+.87i
| .09+.75i .1+.022i .72+.21i .46+.88i .7+.47i .64+.1i .14+.72i
| .1+.016i .47+.55i .15+.054i .43+.55i .25+.94i .23+.13i .44+.16i
| .62+.22i .62+.31i .049+.33i .32+.096i .56+.09i .48+.075i .09+.63i
| .065+.37i .57+.78i .39+.18i .82+.44i .73+.98i .87+.1i .75+.98i
| .04+.99i .29+.62i .98+.66i .56+.57i .26+.002i .17+.81i .42+.37i
| .62+.62i .6+.54i .67+.28i .59+.03i .36+.67i .84+.55i .76+.79i
| .49+.87i .48+.25i .58+.16i .43+.64i .37+.93i .04+.53i .42+.16i
| .9+.15i .031+.33i .2+.91i .84+.67i .51+.6i .1+.23i .36+.34i
-----------------------------------------------------------------------
.98+.52i .6+.82i .74+.39i |
.66+.22i .83+.05i .63+.69i |
.13+.93i .96+.24i .29+.74i |
.75+.91i .22+.036i .68+.73i |
.86+.67i .56+.78i .65+.35i |
.42+.31i .46+.01i .37+.022i |
.16+.25i .91+.09i .84+.18i |
.56+.9i .96+.42i .19+.92i |
.29+.9i .32+.62i .66+.89i |
.9+.15i .72+.6i .99+.26i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .05+.68i 1+.73i |
| .44+.18i .75+.97i |
| .51+.91i .92+.38i |
| .98+.96i .56+.16i |
| .52+.83i .86+.22i |
| .88+.88i .59+.87i |
| .55+.34i .23+.21i |
| .71+.06i .21+.62i |
| .78+.6i .91+.07i |
| .69+.89i .84+.96i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.95-.19i .35+1.1i |
| .15+.082i .85+.32i |
| .15+.51i 1.2-.15i |
| 1.2+.36i .63-.53i |
| -.54-.53i .23+.46i |
| -.71+.65i -.19+.84i |
| .34+.4i -.17-.74i |
| .54-.58i -.94+.12i |
| .94-.81i -.95-.49i |
| -.09+.76i .74-.75i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 7.10889595793335e-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 .49 .6 .2 .71 |
| .83 .93 .98 .19 .66 |
| .66 .34 .33 .099 .46 |
| .41 .49 .48 .0028 .96 |
| .78 .26 .55 .96 .32 |
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.3 -2.8 9.2 -6.5 -1.7 |
| -60 24 -60 52 14 |
| 55 -20 53 -48 -13 |
| -21 7.5 -22 18 6 |
| .54 -1.1 .41 1.2 .054 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 1.06581410364015e-14
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 7.105427357601e-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.3 -2.8 9.2 -6.5 -1.7 |
| -60 24 -60 52 14 |
| 55 -20 53 -48 -13 |
| -21 7.5 -22 18 6 |
| .54 -1.1 .41 1.2 .054 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|