(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 = | .97+.44i .2+.71i .94+.27i .05+.66i .008+.5i .37+.13i .42+.38i
| .42+.77i .08+.55i .3+.91i .5+.11i .72+.84i .47+.14i .83+.16i
| .26+.21i .23+.55i .12+.49i .72+.07i .13+.86i .31+.21i .031+.46i
| .53+.84i .6+.9i .28+.54i .81+.42i .98+.48i .36+.82i .35+.57i
| .51+.47i .33+.67i .1+.96i .59+.91i .2+.6i .9+.14i .23+.82i
| .83+.28i .87+.53i .71+.78i .11+.96i .25+.41i .53+.02i .4+.52i
| .58+.99i .8+.68i .52+.75i .78+.95i .56+.09i .25+.52i .76+.52i
| .09+.87i .18+.69i .24+.078i .85+.16i .47+.51i .73+.78i .3+.51i
| .72+.53i .08+.84i .67+.77i .48+.8i .3+.95i .22+.061i .63+.58i
| .82+.67i 1+.78i .14+.43i .33+.58i .94+.37i .91+.17i .54+.97i
-----------------------------------------------------------------------
.32+.59i .99+.56i .62+.7i |
.72+.22i .09+.68i .98+.53i |
.81+.54i .3+.99i .81+.15i |
.31+.056i .45+.47i .3+.85i |
.81+.65i .84+.76i .056+.078i |
.51+.36i .21+.5i .04+.57i |
.86+.62i .49+.11i .27+.2i |
.88+.29i .43+.48i .63+.79i |
.78+.65i .26+.8i .63+.74i |
1+.68i .62+.99i .14+.41i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .53+.43i .94+.71i |
| .15+.34i .3+.68i |
| .98+.86i .28+.34i |
| .2+.11i .76+.23i |
| .5+.54i .11+.78i |
| .27+.99i .018+.49i |
| .83+.33i .44+.63i |
| .59+.58i .087+.43i |
| .87+.63i .51+.44i |
| .43+.2i .52+.65i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .14-.49i 1.4-.63i |
| -.17+.36i -.19+.76i |
| .79+.48i -.38+.072i |
| .42-.24i .22+.3i |
| -.45+.12i .76-.53i |
| -.58+.11i -.85+.33i |
| -.14-2i -1+.41i |
| .2+.8i .17-.65i |
| -.31-.22i .71+.48i |
| .8+.9i -.15-.45i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 9.55049957678547e-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 = | .83 .25 .72 .95 .83 |
| .047 .82 .59 .95 .99 |
| .19 .13 .046 .1 .65 |
| .72 .7 .56 .74 .84 |
| .61 .68 .89 .56 .54 |
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 = | .05 -1.2 -.25 1.8 -.36 |
| -1.6 .1 -.76 2.1 -.043 |
| .54 .18 .68 -2.7 2.2 |
| .91 .69 -1.8 .74 -1.6 |
| .12 .21 2 -.86 .21 |
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 = 5.55111512312578e-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 = | .05 -1.2 -.25 1.8 -.36 |
| -1.6 .1 -.76 2.1 -.043 |
| .54 .18 .68 -2.7 2.2 |
| .91 .69 -1.8 .74 -1.6 |
| .12 .21 2 -.86 .21 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|