(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 = | .48+.26i .21+.95i .58+.22i .41+.86i .23+.016i .096+.44i .72+.11i
| .42+.12i .46+.6i .34+.16i .23+.5i .26+.97i .68+.01i .29+.74i
| .77+.11i .21+.065i .2+.97i .64+.83i .3+.12i .84+.29i .51+.7i
| .21+.84i .33+.15i .76+.31i .83+.35i .12+.22i .96+.98i .72+.92i
| .69+.84i .33+.18i .41+.9i .13+.75i .51+.01i .48+.48i .94+.33i
| .98+.07i .9+.64i .65+.97i .35+.91i .55+.52i .91+.24i .18+.93i
| .86+.59i .73+.91i .11+.94i .23+.081i .49+.43i .79+.84i .87+.01i
| .75+.92i .01+.58i .6+.92i .48+.63i .7+.12i .72+.71i .24+.45i
| .78+.57i .83+.09i .43+.34i .78+.44i .41+.91i .54+.18i .012+.26i
| .01+.76i .57+.52i .31+.55i .74+.31i .78+.7i .8+.65i .05+.87i
-----------------------------------------------------------------------
.31+.4i .29+.47i .93+.04i |
.31+.22i .26+.74i .28+.18i |
.88+.44i .14+.97i .44+.24i |
.74+.67i .22+.59i .23+.56i |
.59+.82i .78+.45i .58+.98i |
.8+.92i .46+.8i .95+.27i |
.85+.17i .47+.35i .74+.19i |
.9+.26i .31+.54i .62+.85i |
.27+.8i .91+.3i .64+.1i |
.64+.67i .73+.47i .66+.91i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .18+.46i .64+.03i |
| .95+.52i .96+.74i |
| .27+.86i .42+.19i |
| .3+.34i .16+.69i |
| .85+.57i .79+.68i |
| .52+.61i .29+i |
| .98+.13i .4+.75i |
| .047+.19i .55+.11i |
| .42+.26i .65+.05i |
| .94+.33i .82+.34i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.59+.25i -.47+.053i |
| -.47-1.9i -.75+.39i |
| -1.2-.91i -.56+.68i |
| .74-2.1i -.82-1.9i |
| -.7-.15i .47-.55i |
| 2.3+1.1i 1.1-.69i |
| .98-.85i .17-.17i |
| -.31+.092i i |
| 1.4+3.7i 1.6+.61i |
| -1.7+.23i .2+.56i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.21238184313208e-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 = | .12 1 .59 .82 .98 |
| .59 .29 .72 .028 .21 |
| .18 .74 .14 .092 .87 |
| .82 .51 .025 .45 .8 |
| .56 .42 .22 .45 .35 |
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 = | -.86 .28 .16 .28 1.2 |
| -1.5 -1 2.9 -3.6 5.7 |
| .93 1.4 -.96 .38 -1.9 |
| 1.1 -.58 -1.6 .59 .045 |
| 1.2 .65 -1.1 2.9 -4.8 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 5.55111512312578e-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 = | -.86 .28 .16 .28 1.2 |
| -1.5 -1 2.9 -3.6 5.7 |
| .93 1.4 -.96 .38 -1.9 |
| 1.1 -.58 -1.6 .59 .045 |
| 1.2 .65 -1.1 2.9 -4.8 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|