(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 = | .66+.13i .35+.94i .76+.31i .55+.58i .87+.03i .11+.89i .1+.37i
| .74+.39i .54+.3i .94+.61i .15+.38i .16+.11i .39+.66i .11+.6i
| .74+.19i .64+.98i .96+.31i .55+.76i .05+.97i .044+.28i .41+.085i
| .15+.43i .92+.73i .57+.23i .37+.22i .11+.95i .91+.58i .64+.75i
| .17+.23i .52+.96i .57+.69i .14+.35i .37+.73i .22+.87i .94+.3i
| .89+.33i .26+.78i .63+.47i .051+.46i .3+.15i .97+.12i .94+.09i
| .27+.29i .76+.37i .82+.87i .42+.95i .55+.83i .07+.91i .66+.13i
| .96+.01i .98+.94i .48+.87i .57+.55i .021+.11i .26+.06i .34+.55i
| .45+.53i .73+.66i .72+.67i .077+.4i .12+.8i .31+.52i .27+.51i
| .12+.64i .16+.16i .6+.9i .36+.074i .77+.5i .28+.63i .45+.51i
-----------------------------------------------------------------------
.93+.03i .46+.88i .9+.02i |
.68+.79i .059+.088i .84+.51i |
.2+.076i .38+.49i .62+.01i |
.74+.72i .5+.1i .71+.75i |
.57+.13i .062+.39i .1+.66i |
.25+.49i .77+.18i .7+.44i |
.51+.28i .6+.4i .45+.88i |
.97+.09i .99+.65i .81+.83i |
.87+.69i .3+.65i .92+.83i |
.4+.16i .42+.62i .92+.33i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .95+.36i .1+.71i |
| .24+.18i .23+.28i |
| .25+.66i .61+.59i |
| .007+.34i .59+.32i |
| .82+.85i .59+.92i |
| .25+.73i .87+.66i |
| .24+.68i .37+.52i |
| .05+.79i .57+.81i |
| .1+.59i .93+.29i |
| .37+.84i .29+.95i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.4+.96i .54-.14i |
| .02-.87i .12+.039i |
| .91-.45i -.035-.35i |
| -.76+.29i -.2+1.4i |
| 1.1-.05i -.96-.54i |
| .37+.15i .16-.81i |
| -.58-.09i .11+1.7i |
| -.12+.51i .57-.45i |
| -.27+.35i .8-.42i |
| -.015-.1i -.053+.39i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 5.55111512312578e-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 = | .52 .55 .28 .27 .67 |
| .16 .98 .73 .44 .57 |
| .92 .91 .02 .63 .35 |
| .76 .92 .97 .66 .49 |
| .69 .14 .57 .45 .59 |
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 = | 2 -2.6 -.37 2.1 -1.3 |
| 1.2 -.25 .0022 .94 -1.8 |
| .32 -.69 -1.2 1.8 -.46 |
| -5 3.6 2.2 -3.6 3.9 |
| .88 1.1 -.11 -1.7 1.1 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 8.88178419700125e-16
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 = | 2 -2.6 -.37 2.1 -1.3 |
| 1.2 -.25 .0022 .94 -1.8 |
| .32 -.69 -1.2 1.8 -.46 |
| -5 3.6 2.2 -3.6 3.9 |
| .88 1.1 -.11 -1.7 1.1 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|