(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 = | .85+.79i .91+.14i .61+.96i .97+.32i .75+.82i .53+.96i .4+.48i
| .97+.65i .75+.13i .77+.98i .22+.22i .94+.42i .67+.61i .48+.49i
| .77+.05i .9+.28i .57+.15i .78+.33i .57+.84i .56+.46i .088+.26i
| .98+.23i .85+.2i .98+.19i .99+.72i .38+.33i .65+.84i .18+.76i
| .062+.2i .33+.93i .8+.85i .44+.19i .68+.73i .31+.67i .61+.33i
| .79+.7i .47+.93i .34+.85i .48+.68i .85+.26i .97+.87i .43+.18i
| .11+.33i .63+.81i .42+.54i .98+.68i .87+.8i .82+.88i .62+.12i
| .7+.76i .24+.75i .82+.73i .4+.55i .21+i .21+.81i .27+.079i
| .31+.55i .92+.4i .19+.19i .4+.08i .72+.98i .91+.87i .059+.011i
| .76+.03i .43+.92i .54+.9i .94+.22i .6+.82i .16+.58i .006+.09i
-----------------------------------------------------------------------
.46+.64i .8+.88i .71+.07i |
.17+.68i .25+.82i .36+.13i |
.64+.97i .24+.017i .64+.5i |
.65+.88i .02+.6i .16+.69i |
.3+.044i .65+.78i .96+.03i |
.06+.73i .35+.94i .46+.052i |
.91+.28i .92+.64i .34+.77i |
.73+.12i .26+.048i .015+.13i |
.24+.64i .091+.39i .18+.38i |
.08+.9i .71+.68i .32+.8i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .39+.75i .75+.93i |
| .83+.24i .1+.12i |
| .55+.09i .32+.44i |
| .072+.21i .29+.63i |
| .25+.21i .84+.02i |
| .47+.19i .96+.59i |
| .24+.76i .78+.48i |
| .04+.61i .2+.36i |
| .23+.053i .9+.32i |
| .97+.5i .98+.68i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .57+.51i -.39+.33i |
| .37+.028i -.81-.15i |
| -.36-.65i .24-.25i |
| -.017+.36i .6+.53i |
| .39+.28i -.074-.15i |
| -.43-.41i 1.2-.46i |
| 1.1+.43i -1.3+.08i |
| -.45-.17i .05-.11i |
| -.2+.66i .27-.37i |
| .08-.53i .098+.5i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 8.95090418262362e-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 = | .38 .048 .014 .49 .18 |
| .4 .2 .79 .079 .3 |
| .025 .054 .37 .99 .11 |
| .89 .77 .41 .77 .67 |
| .45 .56 .2 .34 .97 |
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.3 .53 -1.2 .26 -.63 |
| -3.3 -1 .24 2.2 -.58 |
| -.73 1.2 .45 -.16 -.18 |
| .29 -.44 .86 .093 -.083 |
| .93 .27 -.0061 -1.4 1.7 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 1.11022302462516e-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 = | 2.3 .53 -1.2 .26 -.63 |
| -3.3 -1 .24 2.2 -.58 |
| -.73 1.2 .45 -.16 -.18 |
| .29 -.44 .86 .093 -.083 |
| .93 .27 -.0061 -1.4 1.7 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|