(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 = | .99+.16i .13+.9i .01+.88i .13+.1i .04+.81i .69+.59i .18+.76i
| .023+.23i .5+.66i .31+.9i .39+.46i .78+.92i .13+.45i .36+.46i
| .9+.45i .82+.86i .36+.59i .09+.79i .21+.31i .62+.69i .94+.69i
| .51+.96i .93+.81i .35+.38i .72+.63i .06+.73i .54+.04i .65+.68i
| .76+.31i .4+.84i .28+.47i .02+.84i .82+.75i .53+.96i .06+.78i
| .85+.49i .48+.3i .92+.22i .4+.62i .85+.37i .99+.09i .62+.04i
| .34+.53i .92+.1i .89+.31i .35+.69i .71+.03i .73+.59i .46+.17i
| .26+.81i .36+.32i .41+.15i .31+.27i .67+.26i .039+.4i .68+.48i
| .81+.34i .06+.72i .1+.41i .38+.48i .02+i .21+.9i .35+.19i
| .24+.18i .95+.16i .86+.25i .17+.57i .4+.58i .078+.31i .85+.64i
-----------------------------------------------------------------------
.6+.19i .66+.26i .083+.38i |
.81+.96i .41+.59i .46+.63i |
.97+.02i .71+.9i .76+.42i |
.77+.44i .02+.67i .3+.042i |
.32+.27i .35+.39i .98+.77i |
.16+.71i .54+.26i .09+.54i |
.15+.65i .95+.58i .05+.52i |
.35+.73i .97+.44i .96+.18i |
.67+.01i .25+.25i .53+.45i |
.48+.21i .28+.002i .028+.3i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .32+.64i .77+.93i |
| .28+.86i .66+.78i |
| .21+.003i .53+.61i |
| .44+.52i .77+.44i |
| .98+.36i .42+.62i |
| .92+.63i .37+.54i |
| .78+.71i .99+.92i |
| .48+.084i .93+.81i |
| .23+.36i .29+.18i |
| .62+.95i .41+.99i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.07-.69i -.73-1.4i |
| .22-.66i 1.5-1.8i |
| -1+.12i -3.1-1.1i |
| 1.2-.21i 2.4+.43i |
| 1.2+.82i 1.1+2i |
| -.23+.083i -.44-.091i |
| .45-.52i 1.7+.14i |
| -.35+.82i -.99+1.1i |
| .16+1.1i .67+2.7i |
| -.7-1.4i -.82-2.8i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.35064460289285e-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 = | .058 .94 .83 .35 .87 |
| .49 .013 .72 .068 .47 |
| .44 .7 .18 .72 .11 |
| .35 .73 .55 .71 .56 |
| .72 .69 .25 .84 .43 |
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 = | .69 1 1 -3.5 1.7 |
| 2 -.14 2.3 -3.6 .24 |
| -.57 1.3 1.9 1.6 -2.8 |
| -2.2 -.7 -1.4 5.1 -.95 |
| .41 -.91 -3.8 .62 2.6 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 5.96744875736022e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 1.22124532708767e-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 = | .69 1 1 -3.5 1.7 |
| 2 -.14 2.3 -3.6 .24 |
| -.57 1.3 1.9 1.6 -2.8 |
| -2.2 -.7 -1.4 5.1 -.95 |
| .41 -.91 -3.8 .62 2.6 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|