(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 |
| -4.4e-16 |
| -2.2e-15 |
3 1
o10 : Matrix RR <--- RR
53 53
|
i11 : norm oo
o11 = 2.22044604925031e-15
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 = | .92+.79i .54+.1i .43+.44i .63+.45i .81+.97i .07+.99i .93+.94i
| .032+.31i .71+.4i .35+.76i .11+.17i .16+.27i .77+.32i .86+.6i
| .81+.26i .12+.74i .41+.85i .9+.37i .072+.49i .01+.62i .69+.32i
| .029+.45i .62+.6i .87+.15i .73+.31i .87+.69i .77+.63i .71+.52i
| .68+.5i .94+.64i .68+.11i .027+.37i .37+.32i .69+.2i .62+.26i
| .28+.005i .57+.84i .58+.98i .33+.91i .56+.83i .72+.48i .67+.23i
| .73+.11i .53+.62i .74+.62i .62+.69i .43+.4i .098+.14i .4+.64i
| .78+.07i .46+.73i .65+.2i .29+.54i .6+.32i .98+.05i .38+.4i
| .45+.14i .37+.79i .31+.18i .66+.75i .59+.77i .6+.36i .45+.049i
| .56+.12i .89+.14i .91+.43i .42+.99i .13+.56i .78+.07i .81+.98i
-----------------------------------------------------------------------
.27+.6i .98+.36i .54+.07i |
.61+.44i .32+.6i .56+.17i |
.48+.84i .78+.46i .2+.98i |
.79+.86i .52+.59i .1+.016i |
.93+.42i .32+.34i .55+.28i |
.85+.93i .2+.077i .12+.98i |
.59+.04i .79+.33i .12+.93i |
.02+.75i .14+.15i .97+.22i |
.74+.13i .48+.94i .074+.49i |
.14+.87i .48+.15i .84+.18i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .11+.27i .81+.23i |
| .17+.013i .74+.03i |
| .042+.21i .31+.95i |
| .93+.03i .48+.19i |
| .93+.78i .47+.4i |
| .48+.78i .92+.36i |
| .39+.75i .96+.78i |
| .21+.39i .79+.58i |
| .88+.78i .22+.61i |
| .8+.34i 1+.8i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .97-2.7i .83+.6i |
| 3.2-3.4i 1.1-.02i |
| -.88-1.3i .19-.54i |
| 5.3-.49i .31+1.6i |
| -3-.72i .4-1.6i |
| 1.7-.69i .01+1.1i |
| .14-.031i .64-.86i |
| -1+3.1i -.68+.34i |
| -3.1+3.6i -1.3 |
| -2.3+3.1i -.71-.38i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 3.28783509194982e-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 = | .95 .48 .76 .91 .18 |
| .37 .47 .77 .33 .84 |
| .57 .96 .75 .8 .94 |
| .58 .82 1 .028 .34 |
| .66 .62 .5 .92 .89 |
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.6 -4.3 2.7 5.2 |
| -.71 -2 1.7 .85 -.076 |
| 1.5 2.3 1.6 -1.3 -3.7 |
| 1.5 .63 2.6 -2.2 -2.8 |
| -1.1 .61 -1.5 .45 2.2 |
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 = 1.08246744900953e-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 = | -1 -1.6 -4.3 2.7 5.2 |
| -.71 -2 1.7 .85 -.076 |
| 1.5 2.3 1.6 -1.3 -3.7 |
| 1.5 .63 2.6 -2.2 -2.8 |
| -1.1 .61 -1.5 .45 2.2 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|