(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 = | .01+.74i .72+.24i .64+.03i .03+.25i .22+.61i .87i .17+.99i
| .88+.08i .2+.27i .89+.69i .35+.38i .95+.57i .92+.6i .14+.67i
| .47+.39i .21+.057i .56+.85i .94+.64i .023+.093i .42+.13i .74+.79i
| .26+.66i .75+.66i .12+.54i .036+.25i .81+.98i .63+.37i .96+.07i
| .44+.26i .99+.47i .38+.23i .84+.98i .63+.82i .64+.56i .3+.74i
| .38+.64i .74+.02i .36+.6i .78+.77i .93+.88i .89+.88i .72+.68i
| .31+.71i .027+.22i .71+.06i .26+.18i .98+.15i .54+.35i .13+.71i
| .52+.37i .94+.24i .55+.68i .65+.28i .98+.71i .68+.86i .093+.061i
| .86+.82i .41+.61i .21+.27i .33+.84i .25+.63i .66+.22i .89+.04i
| .57 .93+.99i .21+.9i .57+.75i .55+.67i .81+.11i .92+.46i
-----------------------------------------------------------------------
.68+.86i .34+.16i .07+.94i |
.81+.29i .24+.36i .18+.46i |
.26+.37i .4+.7i .44+.72i |
.75+.94i .32+.91i .99+.26i |
.63+.98i .51+.96i .86+.76i |
.27+.9i .75+.67i .13+.73i |
.75+.79i .45+.71i .65+.54i |
.99+.36i .85+.23i .1+.88i |
.52+.81i .17+.43i .14+.64i |
.26+.27i .52+.03i .78+.91i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .81+.56i .73+.03i |
| .59+.61i .55+.14i |
| .94+.42i .83+.2i |
| .006+.28i .75+.72i |
| .24+.45i .83+.55i |
| .51+.33i .54+.9i |
| .68+.47i .54+.03i |
| .52+.96i .39+.21i |
| .47+.73i .71+.35i |
| .36+.23i .38+.62i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | 1.2-.77i -.19+.34i |
| .62+.26i .11+.75i |
| .18+.24i .36-.38i |
| .07+.88i -.58-.37i |
| .41-.18i -.65-.23i |
| -.7+.67i .42+.89i |
| .1-.69i .016-.094i |
| -.56+.77i .76-.85i |
| -.04-.55i .39-.007i |
| -.29-.65i -.049-.074i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 7.71185559270127e-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 = | .76 .19 .82 .89 .6 |
| .9 .6 .24 .52 .85 |
| .99 .1 .13 .51 .059 |
| .058 .99 .94 .46 .36 |
| .62 .75 .97 .53 .89 |
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 = | -1 -.63 1.5 -.68 1.5 |
| -.8 .79 .27 1.2 -.72 |
| -.29 -1.8 .61 -.5 2.1 |
| 2.1 1.4 -.97 1.3 -3.3 |
| .4 .95 -1.3 -.77 .35 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 4.44089209850063e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 6.10622663543836e-16
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 = | -1 -.63 1.5 -.68 1.5 |
| -.8 .79 .27 1.2 -.72 |
| -.29 -1.8 .61 -.5 2.1 |
| 2.1 1.4 -.97 1.3 -3.3 |
| .4 .95 -1.3 -.77 .35 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|