(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 = | .16+.31i .5+.82i .97+.89i .55+.75i .5+.022i .95+.54i .8+.54i
| .67+.91i .57+.07i .9+.61i .25+.12i .41+.45i .65+.02i .71+.13i
| .26+.78i .43+.84i .13+.055i .25+.81i .54+.02i .9+.29i .86+.05i
| .39+.89i .13+.02i .97+.45i .61+.37i .62+.46i .07+.32i .85+.06i
| .76+.15i .07+.8i .1+.2i .49+.77i .96+.64i .29+.11i .97+.83i
| .11+.68i .69+.67i .74+.49i .084+.15i .16+.87i .74+.93i .41+.3i
| .93+.86i .38+.6i .58+.51i .79+.9i .51+.46i .95+i .06+.74i
| .63+.03i .67+.84i .46+.53i .42+.031i .5+.87i .7+.56i .37+.14i
| .07+.73i .7+.47i .092+.35i 1+.35i .18+.79i .7+.11i .9+.2i
| .81+.35i .37+.83i .29+.83i .19+.028i .84+.71i .27+.4i .33+.29i
-----------------------------------------------------------------------
.69+.64i .34+.38i .57+.1i |
.67+.96i .34+.27i .99+.2i |
.39+.99i .23+.64i .72+.15i |
.29+.8i .095+.12i .63+.88i |
.6+.51i .49+.77i .26+.92i |
.37+.74i .14+.35i .31+.47i |
.93+.47i .15+.22i .41+.059i |
.24+.26i .96+.26i .66+.82i |
.03+.77i .23+.38i .77+.63i |
.4+.95i .05+.53i .61+.46i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .93+.16i .48+.16i |
| .8i .75+.55i |
| .72+.03i .44+.17i |
| .95+.67i .32+.43i |
| .77+.31i .31+.32i |
| .62+.13i .079+.019i |
| .17+.4i .85+.3i |
| .7+.02i .83+.97i |
| .63+.25i .77+.86i |
| .33+.81i .93+.3i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.01+1.8i .69-.12i |
| -.52+1.1i .53-.17i |
| .6+.48i .55+.26i |
| .99-.58i .65-.15i |
| .23-.44i .5-.31i |
| .36-1.1i -.85-.08i |
| .34+.97i -.25-.68i |
| -.63-2i -1.7-.25i |
| .67-.63i .76-.33i |
| -.95+.41i .54+1.6i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.33688555545767e-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 = | .94 .23 .92 .65 .31 |
| .28 .4 .69 .65 .45 |
| .78 .67 .46 .73 .76 |
| .89 .3 .24 .49 .62 |
| .5 .45 .81 .22 .64 |
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 = | 1.1 -2 .9 -.17 -.024 |
| .92 -3.3 4.9 -4.3 .27 |
| .53 .43 -.77 -.5 .84 |
| -.11 2.2 -.5 .8 -1.7 |
| -2.1 2.6 -3 3.5 .89 |
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 = 7.7715611723761e-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 = | 1.1 -2 .9 -.17 -.024 |
| .92 -3.3 4.9 -4.3 .27 |
| .53 .43 -.77 -.5 .84 |
| -.11 2.2 -.5 .8 -1.7 |
| -2.1 2.6 -3 3.5 .89 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|