(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 = | .72+.56i .78+.17i .51+.75i .02+.89i .58+.94i .39+.99i
| .24+.42i .12+.25i .61+.87i .026+.08i .68+.29i .4+.11i
| .45+.5i .69+.76i .69+.04i .42+.85i .38+.98i .94+.83i
| .23+.31i .12+.034i .62+.64i .95+i .66+.96i .29+.28i
| .21+.9i .1+.12i .14+.94i .02+.71i .29+.027i .17+.8i
| .24+.37i .014+.0051i .94+.8i .75+.66i .59+.8i .61+.11i
| .79+.5i .19+.16i .18+.036i .25+.55i .015+.13i .87+.77i
| .034+.18i .46+.1i .88+.68i .57+.29i .04+.73i .89+.59i
| .92+.18i .15+.43i .68+.3i .82+.6i .54+.6i .037+.027i
| .51+.03i .35+.86i .059+.093i .74+.36i .39+.99i .41+.42i
-----------------------------------------------------------------------
.85+.75i .87+.89i .55+.42i .21+.46i |
.69+.52i .89+.27i .79+.18i .93+.42i |
.41+.35i .72+.27i .005+.44i .37+.5i |
.92+.81i .22+.42i .94+.29i .2+.5i |
.72+.36i .31+.74i .06+.5i .88+.3i |
.69+.58i .73 .06+.97i .71+.25i |
.2+.67i .47+.96i .7+.28i .85+.31i |
.34+.77i .27+.46i .7+.19i .27+.3i |
.063+.17i .36+.94i .86+.17i .29+.16i |
.74+.71i .061+.45i .68+.46i .62+.91i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .71+.75i .26+.022i |
| .79+.56i .86+.41i |
| .8+.75i .96+.75i |
| .93+.94i .96+.93i |
| .26+.22i .93+.44i |
| .45+.83i .49+.95i |
| .47+.65i .69+.01i |
| .22+.66i .88+.46i |
| .27+.067i .58+.68i |
| .29+.29i .62+.7i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | 1.1-.99i -1.7-1.3i |
| -1.4-.33i 1.6-.67i |
| -.85-.55i .19+.57i |
| -.19+.36i 1.3-.45i |
| 2.3-.84i -1.3+1.4i |
| 1.1-i -.53+.95i |
| -.63-.74i .43+.036i |
| -.71+1.2i 1.1-.37i |
| -.03+1.2i .73-.34i |
| -.38+1.2i -.51i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.24126707662364e-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 = | .014 .34 .37 .52 .53 |
| .34 .89 .59 .97 .92 |
| .56 .34 .49 .12 .31 |
| .52 .18 .58 .8 .27 |
| .41 .85 .73 .3 .93 |
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 = | 9.1 2.9 15 -7.6 -11 |
| -17 -.59 -18 9.4 14 |
| -12 -5 -18 11 15 |
| -.25 .9 -.66 .71 -.73 |
| 21 2.9 24 -14 -18 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 3.5527136788005e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 4.44089209850063e-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 = | 9.1 2.9 15 -7.6 -11 |
| -17 -.59 -18 9.4 14 |
| -12 -5 -18 11 15 |
| -.25 .9 -.66 .71 -.73 |
| 21 2.9 24 -14 -18 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|