(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 = | .78+.72i .036+.28i .22+.77i .33+.45i .63+.55i .36+.4i .35+.038i
| .7+.39i .38+.39i .4+.41i .04+.076i .34+.81i .54+.47i .22+.23i
| .26+.35i .36+.85i .91+.97i .037+.25i .65+.24i .73+.51i .33+.54i
| .11+.41i .53+.95i .23+.21i .069+.053i .6+.65i .57+.41i .72+.95i
| .06+.97i .02+.95i .63+.24i .67+.38i .74+.33i .93+.1i .0085+.038i
| .96+.42i .84+.17i .75+.45i .88+.93i .77+.66i .15+.97i .23+.85i
| .58+.56i .58+.14i .58+.59i .72+.36i .87+.34i .091+.19i .71+.33i
| .22+.67i .66+.88i .23+.79i .92+.54i .65+.3i .86+.85i .92+.92i
| .19+.82i .5+.44i .71+.97i 1+.31i .93+.89i .52+.18i .12+.25i
| .88+.8i .36+.43i .77+.01i .56+.54i .7+.28i .79+.78i .71+.15i
-----------------------------------------------------------------------
.71+.96i .34+.47i .46+.82i |
.71+.39i .21+.53i .072+.16i |
.63+.36i .52+.72i .45+.91i |
.22+.44i .23+.87i .53+.93i |
.059+.0085i .89+.93i .72+.26i |
.21+.42i .41+.24i .33+.59i |
.67+.18i .29+.17i .2+.6i |
.86+.05i .51+.47i .65+.43i |
.85+.84i .5+.53i .27+.41i |
.14+.68i .6+.13i .82+.85i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .69+.98i .33+.68i |
| .94+.34i .83+.25i |
| .14+.44i .64+.98i |
| .39+.013i .75+.81i |
| .054+.4i .22+.44i |
| .49+.25i .58+.48i |
| .1+.41i .1+.67i |
| .26+.32i .15+.058i |
| .17+.14i .16+.3i |
| .96+.28i .4+.46i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .45+.68i .2+.81i |
| -.57-.15i .71-.19i |
| -.23+.11i .31+.85i |
| .14+.77i .25+.027i |
| -1-2.1i -1.1+.21i |
| -.31-.41i -.63-.34i |
| .15+.33i .24+.46i |
| .3+.67i .66-.52i |
| 1.7+1.1i 1.1-1.4i |
| .7-.86i -.41-.25i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 9.55049957678547e-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 = | .67 .88 .45 .86 .17 |
| .96 .78 .97 .64 .27 |
| .99 .0062 .88 .22 .6 |
| .11 .41 .89 .63 .13 |
| .65 .99 .035 .75 .89 |
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.3 -.097 .75 -1.3 -.54 |
| -2.1 2.8 -1.8 -.27 .8 |
| -1.3 1.1 -.26 .83 -.039 |
| 3.3 -3.3 1.3 .71 -.6 |
| -1.3 -.3 .35 .59 1.1 |
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 = 8.88178419700125e-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.3 -.097 .75 -1.3 -.54 |
| -2.1 2.8 -1.8 -.27 .8 |
| -1.3 1.1 -.26 .83 -.039 |
| 3.3 -3.3 1.3 .71 -.6 |
| -1.3 -.3 .35 .59 1.1 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|