(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 = | .76+.51i .34+.79i .26+.37i .7+.72i .98+.04i .79+.12i .99+.21i
| .39+.41i .31+.93i .17+.65i .01+.68i .27+.88i .6+.14i 1+.84i
| .21+.18i .88+.65i .82+.06i .04+.72i .17+.39i .61+.17i .86+.79i
| .34+.92i .09+.24i .16+.32i .4+.22i .41+.09i .4+.61i .07+.42i
| .07+.44i .73+.62i .45+.93i .97+.84i .97+.92i .87+.43i .19+.4i
| .88+.25i .13+.017i .7+.22i .27+.52i .62+.61i .05+.54i .96+.7i
| .95+.64i .72+.19i .75+.29i .48+.55i .77+.36i .69+.69i .32+.16i
| .54+.12i .49+.88i .9+.6i .67+.01i .1+.4i .07+.73i .42+.092i
| .09+.24i .31+.78i .18+.31i .66+.52i .99+.96i .07+.64i .6+.15i
| .76+.06i .23+.43i .77+.45i .97+.75i .93+.25i .92+.84i .21+.97i
-----------------------------------------------------------------------
.7+.1i .17+.93i .44+.31i |
.27+.14i .58+.81i .47+.24i |
.6+.64i .89+.24i 1+.53i |
1+.31i .77+.26i .05+.42i |
.2+.7i .43+.55i .3+.77i |
.42+.015i .84+.62i .51+.33i |
.97+.97i .29+.19i .06+.93i |
.17+.74i .55+.06i .24+.52i |
.16+.27i .79+.28i .07+.86i |
.41+.05i .96+.49i .57+.64i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .55+.58i .17+.48i |
| .076+.46i .17+.81i |
| .57+.45i .35+.66i |
| .17+.8i .29+.58i |
| .25+.41i .45+.44i |
| .87+.5i .72+.58i |
| .4+.015i .68+.78i |
| .33+.97i .26+.99i |
| .07+.93i .6i |
| .33+.12i .0053+.038i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.67-2.4i -.76-.48i |
| -.22+.71i -.36+1.1i |
| 2.1+.99i 1.2-.73i |
| -.17+.007i -.48+.08i |
| -1.1-.19i -.6-.29i |
| 1.3-.94i .88-.53i |
| .51+1.9i .76+1.4i |
| -1.6+1.7i .12+.8i |
| -.12-.92i -.035-.34i |
| .9-1.1i .34-.72i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.40543009465556e-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 = | .31 .57 .026 .49 .37 |
| .84 .97 .89 .87 .11 |
| .27 .43 .32 .13 .8 |
| .53 .24 .49 .58 .59 |
| .66 .3 .69 .19 .95 |
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.4 -.46 -5.6 -2.7 5 |
| .53 .67 1.2 -1.6 -.28 |
| -3.3 .99 2.8 1.4 -2 |
| -.5 -.097 .99 2.9 -2.4 |
| -.048 -.59 1.2 .78 -.37 |
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 = 6.66133814775094e-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 = | 3.4 -.46 -5.6 -2.7 5 |
| .53 .67 1.2 -1.6 -.28 |
| -3.3 .99 2.8 1.4 -2 |
| -.5 -.097 .99 2.9 -2.4 |
| -.048 -.59 1.2 .78 -.37 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|