(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 = | .68+.99i .23+.69i .93+.91i .39+.95i .93+.26i .07+.57i .67+.81i
| .31+.23i .93+.45i .27+.6i .57+.87i .13+.13i .8+.02i .1+.054i
| .78+.67i .79+.58i .71+.32i .66+.34i .2+.37i .92+.15i .73+.07i
| .35+.21i .73+.14i .05+.67i .33+.011i .24+.85i .55+.19i .53+.55i
| .45+.99i .41+.88i .32+.91i .23+.62i .74+.01i .85+.14i .52+.05i
| .37+.9i .82+.32i .73+.67i .8+.02i .1+.57i .9+.35i .95+.91i
| .48+.66i .35+.71i .1+.91i .19+.45i .69+.87i .97+.46i .87+.59i
| .095+.37i .63+.22i .31+.086i .54+.7i .16+.58i .88+.54i .3+.75i
| .15+.26i .92+.02i .91+.16i .49+.65i .79+.05i .68+.43i .6+.77i
| .8+.15i .92+.98i .47+.68i .12+.84i .11+.88i .14+.78i .43+.67i
-----------------------------------------------------------------------
.31+.73i .94+.5i .37+.19i |
.42+.096i .13+.53i .44+.76i |
.93+.54i .08+.86i .44+.57i |
.97+.57i .13+.062i .012+.086i |
.087+.05i .04+.56i .75+.16i |
.56+.35i .68+.11i .58+.12i |
.54+.81i .63+.39i .035+.28i |
.39+.65i .091+.078i .009+.42i |
.22+.84i .79+.28i .13+.82i |
.92+.08i .66 .11+.058i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .93+.88i .29+.64i |
| .99+.56i .21+.58i |
| .34+.85i .61+.33i |
| .16+.89i .66+.89i |
| .012+.16i .95+.7i |
| .23+.52i .68+.32i |
| .59+.47i .22+.54i |
| .47+.31i .17+.39i |
| .39+.85i .15+.66i |
| .62+.77i .15+.21i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | 2.5+.2i .8+.95i |
| -1.5+1.9i -.53+.61i |
| -.03-1.1i .56-.82i |
| .23-.46i -.91+.38i |
| -.41-.11i .92i |
| .85-i 1.1-.48i |
| -.97+.1i -.41-1.1i |
| -.09+.52i .55-.11i |
| .45+.6i -.89-.31i |
| .19-1.4i 1.1+.55i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 7.44760245974182e-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 = | .37 .88 .44 .63 .89 |
| .08 .19 1 .17 .2 |
| .19 .98 .51 .48 .052 |
| .37 .31 .089 .59 .51 |
| .38 .38 .82 .73 .38 |
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 = | -14 21 8.2 36 -27 |
| -.4 1.3 1.5 1.9 -2.5 |
| -.53 1.6 .18 .72 -.63 |
| 6.8 -13 -4.2 -18 16 |
| 2.9 -1.9 -2 -3.9 2.4 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 1.77635683940025e-15
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 4.44089209850063e-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 = | -14 21 8.2 36 -27 |
| -.4 1.3 1.5 1.9 -2.5 |
| -.53 1.6 .18 .72 -.63 |
| 6.8 -13 -4.2 -18 16 |
| 2.9 -1.9 -2 -3.9 2.4 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|