(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 = | .39+.65i .5+.71i .84+.95i .37+.17i .05+.93i .56+.13i .9+.73i
| .26+.29i .73+.72i .34+.46i .26+.8i .02+.87i .4+.3i .98+.86i
| .04+.91i .09+.61i .55+.59i .6+.38i .27+.15i .26+.64i .19+.62i
| .01+.53i .53+.89i .17+.69i .25+.89i .81+.37i .78+.68i .1+.52i
| .97+.24i .44+.81i .12+.97i .91+.05i .61+.66i .066+.16i .87+.23i
| .59+.5i .6+.64i .24+.44i .15+.44i .84+.57i .54+.64i .61+.96i
| .8+.35i .24+.11i .16+.33i .54+.12i .41+.81i .21+.12i .89+.72i
| .58+.72i .45+.067i .074+.47i .06+.64i .49+.39i .29+.9i .54+.48i
| .91+.41i .68+.57i .41+.76i .68+.97i .92+.17i .49+.33i .16+.3i
| .91+.19i .075+.24i .35+.71i .25+.079i .35+.27i .49+.73i .48+.95i
-----------------------------------------------------------------------
.56+.06i .38+.86i .29+.99i |
.03+.95i .72+.48i .18+.68i |
.88+.29i .023+.19i .44+.63i |
.69+.21i .95+.96i .76+.2i |
.54+.13i .69+.49i .16+.92i |
.79+.97i .62+.66i .25+.13i |
.85+.04i .82+.74i .59+.17i |
.36+.34i .71+.94i .71+.64i |
.22+.99i .9+.36i .94+.24i |
.42+.23i .78+.06i .23+.89i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .72+.03i .33+.39i |
| .72+.95i .32+.47i |
| .54+.29i .34+.31i |
| .35+.98i .097+.23i |
| .82+.35i .37+.7i |
| .06+.97i .1+.43i |
| .76+.26i .5+.94i |
| .34+.37i .45+.31i |
| .46+.44i .77+.09i |
| .31+.035i .16+.22i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .79-.5i 1.5-.02i |
| 1.4-.4i 1.4-.21i |
| -.46-i .42-1.5i |
| -1.1-.8i -1.5-1.8i |
| -1.7-.92i -1.2-1.5i |
| -.96-.04i -1.6-.87i |
| -.23+.56i -.22+.59i |
| 1.5+.68i 1.1+1.2i |
| .49+1.6i -.47+1.8i |
| .42+.53i .3+1.4i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.93892115658267e-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 = | .73 .052 .98 .25 .11 |
| .37 .72 .58 .75 .13 |
| .27 .38 .4 .87 .98 |
| .64 .53 .77 .89 .12 |
| .61 .45 .49 .4 .86 |
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.6 -3.1 -1.8 3.8 2.2 |
| -.34 2.4 -.84 -1.5 .85 |
| 2.4 2.5 1.1 -3.2 -1.5 |
| -.77 -1.4 .73 2.1 -.82 |
| .28 .15 .75 -1.1 .41 |
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 = 5.27355936696949e-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.6 -3.1 -1.8 3.8 2.2 |
| -.34 2.4 -.84 -1.5 .85 |
| 2.4 2.5 1.1 -3.2 -1.5 |
| -.77 -1.4 .73 2.1 -.82 |
| .28 .15 .75 -1.1 .41 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|