(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 = | -1.1e-16 |
| -7.8e-16 |
| 0 |
3 1
o10 : Matrix RR <--- RR
53 53
|
i11 : norm oo
o11 = 7.7715611723761e-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+.12i .96+.4i .42+.79i .72+.87i .26+.32i .87+.26i .3+.48i
| .72+.48i .49+.37i .34+.002i .89+.42i .56+.69i .093+.38i .42+.68i
| .1+.63i .2+.44i .93+.74i .055+.43i .86+.12i .79+.02i .22+.28i
| .26+.61i .41+.44i .55+.92i .45+.89i .5+.23i .32+.1i .22+.75i
| .43+.34i .56+.17i .87+.22i .024+.48i .85+.85i .68+.27i .8+.44i
| .64+.83i .17+.91i .056+.21i .25+.45i .22+.91i .57+.1i .33+.59i
| .68+.3i .96+.93i .45+.97i .45+.8i .9+.89i .8+.91i .11+i
| .14+.38i .1+.85i .65+.62i .06+.76i .59+.27i .75+.93i .13+.82i
| .74+.07i .91+.76i .38+.8i .13+.41i .54+.76i .58+.33i .77+.22i
| .59+.73i .3+.87i .3+.83i .89+.15i .18+.37i .34+.078i .72+.78i
-----------------------------------------------------------------------
.72+.49i .53+.37i .27+.68i |
.25+.94i .75+.7i .03+.57i |
.81+.75i .92+.1i .82+.81i |
.32+.95i .67+.39i .22+.16i |
.85+.45i .06+.61i .66+.99i |
.85+.76i .52+.07i .65+.77i |
.1+.52i .92+.67i .74+.02i |
.66+.34i .65+.12i .82+.6i |
.79+.56i .62+.55i .63+.11i |
.35+.023i .38+.75i .068+.24i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .69+.22i .14+.89i |
| .57+.82i .75+.23i |
| .41+.9i .52+.51i |
| .82+.77i .42+.37i |
| .43+.34i .12+.2i |
| .73i .25+.44i |
| .31+i .049+.024i |
| .95+.19i .84+.59i |
| .63+.41i .38+.46i |
| .95+.27i .63+.17i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.71+.78i -3.3+1.5i |
| .87-.59i 2-2.6i |
| -.19+.32i -.17+1.1i |
| -.7-.3i .71-.25i |
| -.04+1.1i .12+.5i |
| -1.1+.49i -1.9+1.1i |
| .69-1.7i .52-.9i |
| .88+.52i .58+.27i |
| .92-.44i .8-.15i |
| -.38-.51i .2-1.2i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.05325004057301e-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 = | .34 .091 .56 .6 .22 |
| .85 .23 .55 .54 .63 |
| .47 .1 .39 .74 .75 |
| .7 .91 .73 .75 .66 |
| .44 .004 .098 .32 .13 |
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 = | -.59 1.2 -1 -.14 1.7 |
| -.83 -.96 -.31 1.5 .49 |
| 2 1.8 -1.2 -.53 -3 |
| .7 -2.6 1.1 .45 2.5 |
| -1.3 .94 1.5 -.27 -2 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 4.44089209850063e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 4.44089209850063e-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 = | -.59 1.2 -1 -.14 1.7 |
| -.83 -.96 -.31 1.5 .49 |
| 2 1.8 -1.2 -.53 -3 |
| .7 -2.6 1.1 .45 2.5 |
| -1.3 .94 1.5 -.27 -2 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|