(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 = | .35+.22i .63+.4i .21+.42i .055+.28i .98+.59i .91+.42i .96+.69i
| .63+.22i .06+.95i .1+.39i .042+.063i .36+.61i .39+.89i .73+.2i
| .42+.44i .26+.074i .12+.2i .5+.89i .53+.3i .3+.27i .39+.66i
| .28+.15i .33+.73i .51+.45i .96+.74i .03+.86i .57+.8i .99+.84i
| .031+.3i .89+.14i .04+.71i .97+.87i .29+.81i .06+.91i .54+.54i
| .52+.94i .4+.3i 1+.37i .73+.45i .29+.09i 1+.1i .089+.14i
| .07+.78i .31+.96i .41+.06i .53+.49i .36+.8i .56+.65i .79+.21i
| .23+.76i .01+.94i .51+.13i .57+.47i .91+.41i .13+.8i .06+.99i
| .01+.78i .6+.22i .56+.34i .62+.36i .86+.16i .72+.08i .74+.13i
| .42+.13i .6+.19i .83+.19i .67+.73i .74+.36i .4+.36i .69+.17i
-----------------------------------------------------------------------
.61+.97i .68+.42i .67+.08i |
.82+.72i .95+.22i .04+.31i |
.77+.38i .97+.98i .19+.048i |
.23+.94i .092+.48i .05+.52i |
.83+.3i .027+.22i .87+.39i |
.39+.6i .5+.64i .14+.24i |
.76+.16i .32+.44i .99+.44i |
.88+.86i .73+.2i .92+.97i |
.9+.67i .51+.28i .74+.96i |
.54+.91i .7+.83i .92+.61i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .62+.17i .67+.54i |
| .16+.69i .8+.29i |
| .31+.7i .9+.24i |
| .74+.02i .77+.69i |
| .66+.5i .3+.52i |
| .67+.86i .75+.65i |
| .37+.061i .64+.18i |
| .63+.23i .028+.29i |
| .38+.44i .46+.024i |
| .06+.52i .72+.66i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .5+.24i .044-.33i |
| -.85+.31i .22+.71i |
| -.22-.38i .49+.91i |
| .43-.34i -.34-.33i |
| -.22-.72i -.32-.49i |
| 1+.58i .26-.54i |
| -.46-.39i .44+.1i |
| .34-.094i .27-.089i |
| -.11+.73i .4+.12i |
| .43+.003i -.49+.1i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 4.96506830649455e-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 = | .92 .77 .012 .27 .074 |
| .2 .89 .02 .25 .86 |
| .59 .61 .6 .45 .29 |
| .75 .49 .13 .36 .16 |
| .98 .5 .41 .74 .23 |
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 = | -4.2 -.92 .52 12 -4.5 |
| 5.2 .71 .087 -11 3.1 |
| -2.1 -.78 2.6 4 -2.5 |
| 5 1.1 -2.3 -15 8 |
| -5.8 .35 .4 13 -4.4 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 1.77635683940025e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 1.33226762955019e-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 = | -4.2 -.92 .52 12 -4.5 |
| 5.2 .71 .087 -11 3.1 |
| -2.1 -.78 2.6 4 -2.5 |
| 5 1.1 -2.3 -15 8 |
| -5.8 .35 .4 13 -4.4 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|