(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 |
| 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 = | .67+.25i .54+.78i .76+.65i .34+.47i .96+.43i .5+.06i .15+.89i
| .11+.27i .95+.13i .63+.7i .53+.39i .71+.16i .87+.67i .48+.19i
| .56+.17i .55+.88i .81+.7i .13+.29i .21+.36i .52+.59i .57+.44i
| .055+.29i .56+.52i .47+.29i .19+.6i .39+.42i .65+.41i .93+.6i
| .68+.88i .61i .57+.86i .79+.67i .51+.24i .19+.91i .19+.3i
| .9+.82i .61+.65i .21+.14i .2+.68i .64+.68i .65+.84i .14+.034i
| .91+.92i .92+.22i .61+.51i .19+.039i .58+.06i .58+.72i .44+.98i
| .5+.43i .59+.51i .6+.63i .11+.66i .85+.58i .75+.71i .26+.23i
| .39+.49i .11+.036i .66+.57i .91+.81i .78+.24i .63+.35i .86+.35i
| .08+.53i .4+.17i .7+.11i .06+.76i .42+.37i .92+.16i .39+.31i
-----------------------------------------------------------------------
.1+.63i .27+.86i .72+.05i |
.15+.57i .64+.8i .71+.73i |
.41+.11i .72+.75i .37+.89i |
.077+.39i .71+.61i .76+.95i |
.38+.24i .19+.58i .09+.56i |
.36+.35i .55+.22i .1+.98i |
.062+.088i .77+.72i .31+.2i |
.29+.68i .22+.35i .81+.17i |
.77+.02i .29+.66i .38+.097i |
.39+.51i .062+.48i .43+.88i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .97+.87i .68+.81i |
| .11+.38i .61+.15i |
| .66+.99i .43+.034i |
| .41+.38i .77+.36i |
| .76+.19i .034+.42i |
| .55+.13i .66+.72i |
| .88 .17+.41i |
| .96+.59i .6+.32i |
| .22+.39i .076+.014i |
| .39+.66i .25+.56i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .24-.24i .14+.36i |
| -.18-.57i -.15-.44i |
| .97+.53i -.67+.38i |
| -1.2-1.1i -.17+.088i |
| .83+1.3i .5+.52i |
| -.84-.48i -.12i |
| -.37+.2i .11-.063i |
| -.22+.65i .4-.72i |
| .26-.095i .37-.13i |
| .79+.15i .31-.18i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 4.23670474327502e-16
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 = | .3 .63 .22 .96 .35 |
| .72 .17 .17 .95 .37 |
| .31 .17 .45 .0029 .68 |
| .38 .62 .87 .23 .16 |
| .023 .24 .82 .67 .58 |
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 = | -.68 1.2 .35 .65 -.95 |
| 1.7 -1.1 .47 .47 -.98 |
| -1 .22 -.54 .79 .91 |
| .17 .46 -.87 -.34 .7 |
| .6 -.43 1.6 -.95 .067 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 2.22044604925031e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 2.22044604925031e-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 = | -.68 1.2 .35 .65 -.95 |
| 1.7 -1.1 .47 .47 -.98 |
| -1 .22 -.54 .79 .91 |
| .17 .46 -.87 -.34 .7 |
| .6 -.43 1.6 -.95 .067 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|