(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 = | .8+.35i .95 .22+.3i .58+.51i .27+.001i .44+i
| .78+.77i .34+.11i .38+.57i .09+.66i .08+.64i .68+.18i
| .94+.03i .72+.61i .86+.57i .13+.002i .1+.61i .25+.31i
| .26+.44i .0023+.041i .92+.41i .27+.55i 1+.28i .27+.067i
| .67+.83i .72+.64i .43+.067i .12+.83i .39+.56i .73+.26i
| .31+.63i .04+.74i .9+.54i .59+.52i .81+.28i .88+.86i
| 1+.44i .71+.25i .33+.55i .62+.52i .61+.71i .99+.81i
| .75+.32i .11+.24i .39+.063i .73+.02i .86+.4i .58+.22i
| .81+.59i .95+.58i .66+.43i .16+.21i .62+.8i .29+.65i
| .55+.52i .43+.53i .84+.12i .32+.26i .59+.13i .38+.81i
-----------------------------------------------------------------------
.19+.019i .67+.42i .6+.68i .02+.53i |
.28+.071i .33+.027i .79+.21i .4+.16i |
.66+.52i .1+.55i .18+.21i .66+.77i |
.58+.91i .12+.33i .71+.56i .55+.93i |
.25+.91i .14+.35i .15+.96i .67+.06i |
.57+.03i .73+.07i .85+.32i .29+.95i |
.1+.22i .18+.23i .51+.7i .68+.85i |
.67+.11i .14+.24i .7+.63i .29+i |
.96+.54i .5+.13i .46+.085i .7+.11i |
.34+.48i .66+.32i .52+.27i .098+.3i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .16+.34i .71+.55i |
| .5+.72i .11+.44i |
| .94+.14i .78+.58i |
| .63+.82i .56+.67i |
| .8+.83i .85+.1i |
| .54+.37i .3+.47i |
| .38+.28i .68+.08i |
| .66+.2i .66+.82i |
| .88+.89i .49+.3i |
| .61+.3i .59+.35i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | 1.9+.87i 2.3+.83i |
| -1.1-.69i -1.2-.42i |
| 1.4-.67i .88-.4i |
| -.37+.35i -.5+.41i |
| -.38+.65i -.19+.76i |
| -1.5-.43i -2.1-.15i |
| .28+.069i -.53+.08i |
| -.06+3.2i 1.6+3.3i |
| .13-2.7i -.59-3.1i |
| .44+.78i 1.2+.07i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.49365231817119e-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 = | .82 .38 .16 .87 .35 |
| .49 .65 .51 .68 .15 |
| .19 .54 .63 .2 .29 |
| .33 .22 .18 .72 .14 |
| .0094 .63 .7 .94 .42 |
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 = | .013 -.56 2.1 2.7 -2.1 |
| 2.4 4.5 -5 -9.9 3.2 |
| -3.3 -2.6 5.5 9.1 -3.2 |
| -.54 .022 -.78 1.8 .37 |
| 3.1 -2.4 .036 -4.1 2.1 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 6.66133814775094e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 1.77635683940025e-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 = | .013 -.56 2.1 2.7 -2.1 |
| 2.4 4.5 -5 -9.9 3.2 |
| -3.3 -2.6 5.5 9.1 -3.2 |
| -.54 .022 -.78 1.8 .37 |
| 3.1 -2.4 .036 -4.1 2.1 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|