(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 = | .14+.57i .43+.82i .72+.79i .59+.73i .93 .33+.86i .49+.27i
| .2+.38i .95+.98i .26+.24i .47+.79i .74+.11i .17+.4i .47+.065i
| .89+.53i .5+.88i .77+.25i .83+.62i .45+.86i .79+.93i .01+.53i
| .91+.81i .57+.62i .95+.38i .9+.69i .98+.53i .84+.67i .72+.45i
| .33+.059i .15+.97i .95+.25i .89+.74i .73+.47i .35+.44i .7+.42i
| .18+.28i .99+.39i .87+.69i .85+.33i .99+.84i .88+.4i .49+.61i
| .91+.3i .03+.85i .17+.45i .38+.82i .55+.08i .64+.89i .1+.13i
| .4+.28i .81+.83i .92+.32i .3+.66i .09+.63i .35+.29i .61+.84i
| .44+.74i .53+.53i .87+.74i .52+.78i .51+.12i .1+.98i .39+.003i
| .022+.34i .19+.44i .63+.49i .76+.23i .32+.36i .46+.4i .98+.72i
-----------------------------------------------------------------------
.81+.64i .35+.56i .52+.04i |
.13+.85i .54+.85i .27+.96i |
.23+.095i .36+.97i .59+.05i |
.072+.32i .21+.044i .94+.2i |
.67+.1i .61+.86i .086+.31i |
.41+.25i .96+.15i .64+.73i |
.91+.05i .49+.64i .46+.82i |
.06+.75i .1+.6i .15+.15i |
.92+.35i .84+.71i .85+.16i |
.62+.7i .76+.1i .46+.29i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .16+.033i .34+.27i |
| .47+.78i .068+.47i |
| .51+.84i .87+.43i |
| .74+.97i .96+.37i |
| .35+.96i .16+.3i |
| .11+.85i .02+.64i |
| .64+.41i .33+.92i |
| .14+.48i .34+.64i |
| .03+.89i .04+.6i |
| .78+.85i .03+.69i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .36-.046i -.3-.46i |
| -.54-1.1i .35-.44i |
| -.22+1.2i -.96+.96i |
| .35+.13i .03-.89i |
| .071-.34i .12-.37i |
| -.15+.47i .44+.5i |
| -.63-.03i .042-.39i |
| .54-i .57+.34i |
| .46+.88i -.35+.16i |
| .71+.11i .8+.81i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 8.00593208497344e-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 = | .59 .31 .35 .42 .13 |
| .6 .15 .95 .22 .036 |
| .33 .8 .15 .65 .023 |
| .86 .067 .3 .65 .86 |
| .64 .21 .43 .25 .11 |
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 -1.5 -.89 -.46 3 |
| -9.6 -.06 3.3 .52 6.5 |
| -1.6 1.9 .49 .26 -.85 |
| 12 .38 -2.3 -.53 -9.6 |
| -8.8 .55 2.2 1.9 4 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 1.11022302462516e-15
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 = | 1.1 -1.5 -.89 -.46 3 |
| -9.6 -.06 3.3 .52 6.5 |
| -1.6 1.9 .49 .26 -.85 |
| 12 .38 -2.3 -.53 -9.6 |
| -8.8 .55 2.2 1.9 4 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|