(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 = | .98+.89i .01+.9i .89+.55i .19+.94i .16+.6i .05+.26i .03+.38i
| .31+.38i .44+.22i .88+.97i .22+.41i .07+.82i .08+.63i .37+.44i
| .94+.44i .46+.65i .17+.7i .63+.93i .34+.41i .83+.2i .5+.79i
| .08+.82i .86+.1i .82+.12i .18+.46i .07+.65i .53+.85i .12+.78i
| .68+.68i .48+.74i .84+.45i .25+.72i .52+.5i .51+.2i .94+.45i
| .88+.71i .63+.85i .73+.71i .25+.71i .39+.046i .23+.58i .86+.18i
| .47+.96i .32+.083i .39+.94i .5+.89i .35+.76i .28+.62i .92+.58i
| .63+i .69+.48i .042+.13i .93+.16i .35+.24i .85+.26i .88+.46i
| .85+.71i .01+.68i .15+.84i .17+.87i .99+.04i .9+.92i .79+.77i
| .94+.42i .4+.059i .68+.53i .91+.47i .74+.44i .69+.91i .78+.07i
-----------------------------------------------------------------------
.54+.79i .78+.79i .28+.94i |
.83+.83i .08+.92i .37+.88i |
.75+.01i .98+.88i .24+.29i |
.85+.49i .25+.18i .4+i |
.4+.33i .52+.55i .25+.41i |
.25+.91i .9+.77i .46+.21i |
.26+.33i .05+.62i .85+.36i |
1+.69i .14+.006i .12+.43i |
.24+.18i .73+.66i .33+.1i |
.91+.89i .9+.92i .85+.9i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .87+.26i .22+.6i |
| .12+.62i .34+.63i |
| .85+.09i .18+.33i |
| .13+.19i .88+.28i |
| .55+.71i .87+.63i |
| .73+.35i .94+.19i |
| .049+.27i .29+.14i |
| .48 .3+.81i |
| .88+.33i .52+.31i |
| .23+.42i .78+.26i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.28-.41i .053-.025i |
| .38+.44i .93-.6i |
| .11-.33i -.11+.19i |
| -.18-.97i -.7+.48i |
| 1.6+.99i .19-.44i |
| -.62+1.1i .55-.33i |
| -.65-.35i .15+.69i |
| .9-.43i -.56+.28i |
| .15+.006i .098-.12i |
| -.29+.33i .43-.5i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 7.06677886012864e-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 .85 .42 .39 .38 |
| .85 .54 .51 .2 .43 |
| .29 .17 .7 .41 .76 |
| .25 .66 .7 .72 .19 |
| .69 .49 .55 .51 .5 |
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.2 .86 -1.1 -.41 2 |
| 2.3 -.096 .16 .088 -1.9 |
| -1.8 3.1 .85 2 -3.4 |
| -.4 -2.8 -.97 -.094 4.3 |
| 1.8 -1.7 1.4 -1.7 .54 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 4.9960036108132e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 4.71844785465692e-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.2 .86 -1.1 -.41 2 |
| 2.3 -.096 .16 .088 -1.9 |
| -1.8 3.1 .85 2 -3.4 |
| -.4 -2.8 -.97 -.094 4.3 |
| 1.8 -1.7 1.4 -1.7 .54 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|