(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 = | .74+.97i .3+.84i .33+.8i .73+.77i .24+.38i .31+.99i .23+.59i
| .86+.54i .38+.96i .12+.5i .73+.14i .34+.83i .85+.63i .33+.7i
| .46+.47i .46+.48i .92+.09i .63+.73i .58+.97i .46+.52i .42+.35i
| .29+.96i .26 .49+.003i .29+.93i .28+.67i .86+.38i .81+.41i
| .37+.78i .51+.92i .51+.84i .46+.86i .28+.36i .23+.54i .91+.45i
| .73+.09i .45+.3i .59+.78i .16+.72i .29+.56i .78+.63i .64+.67i
| .2+.99i .51+.43i .58+.66i .02+.94i .39+.81i .15+.55i .88+.29i
| .42+.8i .9+.4i .96+.02i .38+.56i .24+.84i .95+.65i .26+.52i
| .62+.52i .95+.35i .75+.46i .9+.28i .9+.39i .48+.65i .63+.91i
| .46+.51i .81+.39i .94+.89i .2+.25i .81i .64+.09i .57+.26i
-----------------------------------------------------------------------
.68+.15i .88+.7i .58+.94i |
.63+.5i .36+.25i .78+.38i |
.066+.12i .1+.32i .46+.88i |
.92+.13i .67+.74i .46+.73i |
.95+i .03+.77i .61+.95i |
.46+.16i .72+.21i .06+.49i |
.69+.66i .02+.52i .43+.48i |
.16+.95i .07+.65i .65+.72i |
.81+.08i .37+.45i .23+.005i |
.88+.61i .11+.26i .27+.63i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .6+.45i .53+.81i |
| .32+.3i .53+.36i |
| .02+.54i .076+.45i |
| .54+.31i .47+.99i |
| .59+.17i .4+.71i |
| .64+.65i .47+.65i |
| .46+.2i .72+.9i |
| .36+.91i .71+.41i |
| .22+.47i .74+.1i |
| .68+.49i .02+.53i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.31-.19i -.51-.82i |
| -.43-.92i -2.3-4.4i |
| .91+.72i 3.8+2.3i |
| -.8+.55i -1.2+.73i |
| .76+.17i .63+.21i |
| -.37+.087i -.62+.65i |
| -.046+.24i .72+.59i |
| .64-1.2i -.15-2i |
| 1.9+.89i 4-.23i |
| -.56-.17i -1.7+3i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.37327003955667e-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 = | .065 .23 .14 .99 .27 |
| .49 .11 .58 .2 .16 |
| .61 .56 .11 .84 .51 |
| .74 .46 .29 .5 .81 |
| .12 .083 .74 .41 1 |
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 = | 2.5 .88 -5 5.1 -2.4 |
| -6.7 -.46 12 -9.5 3.5 |
| -1.9 1.3 3.4 -3.7 1.6 |
| 2.5 .17 -2.4 1.8 -.95 |
| .64 -1.1 -1.9 2.2 .18 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 8.88178419700125e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 2.1094237467878e-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 = | 2.5 .88 -5 5.1 -2.4 |
| -6.7 -.46 12 -9.5 3.5 |
| -1.9 1.3 3.4 -3.7 1.6 |
| 2.5 .17 -2.4 1.8 -.95 |
| .64 -1.1 -1.9 2.2 .18 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|