(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 = | .5+.75i .6+.66i .15+.93i .89+.48i .017+.29i .76+.89i .59+.06i
| .096+.024i .19+.26i .96+.1i .57 .54+.44i .3+.31i .68+.45i
| .019+.41i .97+.93i .56+.03i .73+.38i .49+.74i .24+.71i .27+.91i
| .23+.47i .16+.38i .78+.23i .61+.45i .53+.58i .09+.91i .71+.68i
| .41+.46i .82+.86i .45+.87i .17+.81i .34+.47i .5+.47i .26+.12i
| .82+.41i .46+.29i .78+.92i .81+.47i .093+.18i .95+.15i .72+.71i
| .84+.59i .96+.95i .34+.63i .91+.51i .12+.099i .092+.29i .52+.84i
| .49+.28i .029+.11i .93+.29i .58+.86i .58+.77i .91+.01i .04+.94i
| .96+.3i .97+.1i .49+.5i .09+.63i .45+.79i .89+.22i .36+.17i
| .08+.85i .48+.66i .56+.83i .1+.43i .78+.19i .036+.41i .82+.75i
-----------------------------------------------------------------------
.18+.85i .027+.04i .53+.56i |
.75+.75i .95+.05i .49+.89i |
.43+.19i .46+.53i .14+.51i |
.9+.36i .39+.19i .87+.12i |
.11+.69i .78+.1i .63+.46i |
.42+.32i .25+.49i .01+.87i |
.65+.07i .67+.08i .51+.63i |
.22+.052i .96+.71i .19+.49i |
.52+.84i .53i .55+.56i |
.63+.56i .47+.68i .32+.98i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .7+.4i .28+.57i |
| .99+.58i .01+.51i |
| .8 .02+.75i |
| .81+.62i .25+.9i |
| .48+.42i .05+.74i |
| .26+.49i .33+.92i |
| .42+.22i .1+.23i |
| .97+.86i .89+.97i |
| .039+.093i .29+.16i |
| .25+.8i .73+.98i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .82+.12i .67-1.9i |
| -.69-.52i -.41+.37i |
| .83+.21i .8-.02i |
| .52+.61i .75 |
| 1.5+.36i 1.3-i |
| .01-i -.84+.59i |
| -1.4+.21i -.05+1.4i |
| -.74+.42i -.53+.79i |
| -.35+.45i -.26+.4i |
| .52-.98i -.6-.4i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.30429058107358e-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 = | .5 .18 .11 .6 .88 |
| .77 .26 .24 .046 .3 |
| .37 .61 .062 .54 .11 |
| .9 .24 .79 .66 .53 |
| .075 .82 .63 .23 .75 |
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 = | -.036 1.3 .14 .0052 -.5 |
| -.43 .51 .98 -.66 .62 |
| -.87 -.57 -.66 1.2 .5 |
| .39 -1.4 .9 .7 -.5 |
| 1.1 .23 -.8 -.5 .44 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 2.22044604925031e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 2.22044604925031e-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 = | -.036 1.3 .14 .0052 -.5 |
| -.43 .51 .98 -.66 .62 |
| -.87 -.57 -.66 1.2 .5 |
| .39 -1.4 .9 .7 -.5 |
| 1.1 .23 -.8 -.5 .44 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|