(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 = | .19+.34i .5+.66i .7+.84i .32+.084i .66+.4i .25+.93i .48+.64i
| .93+.04i .67+.87i .41+.92i .94+.37i .85+.14i .52+.43i .89+.33i
| .13+.95i .72+.31i .59+.73i .37+.14i .91+.12i .66+.21i .27+.34i
| .6+.02i .85+.3i .69+.98i .43+.48i .67+.57i .41+.84i .19+.83i
| .82+.73i .48+.19i .23+.34i .58+.05i .1+.92i .47+.71i .68+.86i
| .39+.22i .4+.78i .67+.93i .59+.01i .45+.48i .06+.44i .98+.41i
| .86+.2i .77+.06i .11+.17i .47i .21+.66i .89+.1i .66+.8i
| .28+.04i .84+.23i .89+.97i .93+.68i .24+.22i .13+.21i .75+.72i
| .87+.2i .91+.79i .12+.66i .45+.21i .41+.27i .37+.16i .63+.57i
| .14+.52i .54+.74i .11+.025i .5+.9i .41+.9i .78+.63i .41+.58i
-----------------------------------------------------------------------
.83+.22i .96+.48i .45+.07i |
.16+.24i .91+.97i .04+.82i |
.1+.23i .98+.65i .005+.3i |
.98+.69i .45+.087i .96+.51i |
.14+.31i .21+.6i .91+.64i |
.049+.0014i .81+.33i .92+.2i |
.088+.15i .83+.43i .19+.93i |
.99+.6i .12+.045i .29+.64i |
.43+.92i .17+.97i .42+.57i |
.97+.74i .21+.33i .3+.95i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .77+.87i .4+.48i |
| .89+.89i .27+.34i |
| .54+.02i .7+.4i |
| .47+.97i .36+.95i |
| .53+.81i .16+.35i |
| .66+.21i .87+.29i |
| .82+.96i .53+.35i |
| .99+.41i .069+.048i |
| .24+.23i .31+.59i |
| .2+.41i .65+.24i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.9+.44i .045-.22i |
| .03+.61i -.22-.57i |
| -.68-.48i .94+.46i |
| -.07+1.4i -.16-1.7i |
| .99+.2i -.77+.34i |
| .3-.64i .51+.68i |
| 1.6-i -.57+.35i |
| -.18-.35i -.17+.24i |
| -.19+.86i .61-.87i |
| -.79-.78i 1.3+.73i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.21745459266472e-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 = | .98 .17 .34 .79 .45 |
| .53 .078 .0097 .46 .48 |
| .033 .049 .12 .25 .55 |
| .68 .6 .32 .16 .85 |
| .089 .11 .23 .7 .025 |
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.1 .25 -.94 -.075 -1 |
| -2.4 1.7 -2.7 2 2.1 |
| 3 -5.2 2.5 -.23 -.8 |
| -.74 1.4 -.36 -.22 1.5 |
| -.15 .3 1.8 -.025 -.64 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 2.63677968348475e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 6.66133814775094e-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.1 .25 -.94 -.075 -1 |
| -2.4 1.7 -2.7 2 2.1 |
| 3 -5.2 2.5 -.23 -.8 |
| -.74 1.4 -.36 -.22 1.5 |
| -.15 .3 1.8 -.025 -.64 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|