(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+.04i .93+.07i .48+.21i .46+.27i .095+.28i .12+.11i .082+.21i
| .76+.67i .35+.46i .96+.9i .43+.83i .69+.68i .71+.96i .43+.13i
| .77+.29i .11+.89i .61+.63i .4+.15i .4+.79i .49+.57i .78+.95i
| .01+.68i .48+.3i .11+.15i .19+.15i .49+.65i .28+.66i .37+.016i
| .26+.074i .7+.28i .78+.29i .16+.18i .37+.67i .94+.23i .58+.27i
| .51+.97i .72+.22i .37+.34i .92+.12i .42+.21i .47+.003i .09+i
| .32+.43i .8+.9i .62+.36i .25+.64i .77+.56i .3+.38i .67+.35i
| .41+.14i .44+.15i .7+.63i .92+.34i .03+.93i .4+.78i .92+.33i
| .83+.14i .48+.017i .5+.98i .41+.54i .22+.023i .09+.8i .33+.27i
| .78+.41i .69+.83i .57+.11i .23+.49i .88+.68i .86+.19i .23+.44i
-----------------------------------------------------------------------
.09+.81i .94+.78i .27+.48i |
.64+.77i .53+.97i .59+.08i |
.67+.62i .39+.3i .68+.86i |
.91+.38i .62+.37i .11+.93i |
.43+.72i .48+.91i .92+.91i |
.23+.74i .62+.23i .91+.84i |
.35+.19i .44+.69i .18+.29i |
.27+.26i .85+.18i .12+.18i |
.03+.55i .97+.11i .96+.6i |
.55+.49i .56+.36i .47+.66i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .86+.43i .6+.45i |
| .16+.53i .52+.53i |
| .34+.12i .23+.75i |
| 1+.97i .27+.15i |
| .77+.29i .7+.26i |
| .12+.44i .72+.84i |
| .58+.99i .23+.35i |
| .9+.37i .04+.94i |
| .68+.46i .25+.43i |
| .36+.37i .4+.17i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | 1.6-1.4i -.52+.16i |
| .63+2i .61-.34i |
| 5.3+.46i -.8-.58i |
| -.51-2.9i -.41+2i |
| -2.3-1.4i .87+.35i |
| -3.2+2.5i .94-.81i |
| -.03+1.4i -.35-.55i |
| 1.8+1.8i -.43-.64i |
| -2.1+1.4i .82-.46i |
| -.52-3.4i .05+1.1i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.94209711474168e-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 = | .57 .37 .21 .34 .033 |
| .14 .8 .082 .5 .82 |
| .77 .26 .16 .36 .31 |
| .61 .79 .93 .35 .23 |
| .83 .94 1 .64 .94 |
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 = | -3.7 .55 4.6 2.7 -2.5 |
| -4 2.4 3.5 4.6 -4.2 |
| 1.9 -1.5 -2.7 -1.4 2.5 |
| 13 -2.7 -10 -8.7 7.3 |
| -3.4 .54 2.2 .49 -.14 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 1.33226762955019e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 2.44249065417534e-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 = | -3.7 .55 4.6 2.7 -2.5 |
| -4 2.4 3.5 4.6 -4.2 |
| 1.9 -1.5 -2.7 -1.4 2.5 |
| 13 -2.7 -10 -8.7 7.3 |
| -3.4 .54 2.2 .49 -.14 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|