(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 = | .034+.038i .34+.64i .5+.29i .81+.13i .75+.91i .68+.27i .29+.73i
| .61+.4i .64+.34i .67+.73i .53+.42i .48+.92i .74+.55i .2+.93i
| .16+.78i .27+.29i .94+.36i .91+.99i .74+.15i .46+.002i .19+.025i
| .16+.19i .12+.98i .94+.8i .72+.75i .62+.66i .73+.05i .89+.66i
| .64+.59i .98+.37i .69+.09i .37+.22i .28+i .42+.049i .49+.31i
| .28+.57i .08+.63i .8+.53i .83+.96i .77+.24i .48+.73i .83+.41i
| .61+.79i .18+.65i .68+.8i .83+.1i .5+.51i .59+.39i .059+.071i
| .79+.62i .69+.24i .94+.96i .24+.041i .83+.69i .76+.02i .26+.84i
| .93+.33i .87+.61i .49+.44i .34+.13i .04+.19i .25+.013i .03+.78i
| .039+.06i .89+.04i .56+.88i .2+.25i .58+.1i .17+.047i .03+.68i
-----------------------------------------------------------------------
.18+.12i .82+.18i .61+.68i |
.76+.71i .15+.52i .91+.57i |
.91+.85i .26+.38i .36+.95i |
.83+.65i .44+.67i .3+.33i |
.62+.82i .77+.77i .24+.7i |
.018+.12i .42+.48i .78+.02i |
.09+.84i .48+.74i .69+.8i |
.36+.49i .62+.51i .96+.42i |
.65+.69i .45+.033i .28+.32i |
.44+.32i .17+.053i .079+.29i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .54+.06i .31+.57i |
| .76+.48i .77+.93i |
| .68+.3i .21+.83i |
| .04+.64i .72+.65i |
| .64+.3i .14+.26i |
| .39+.71i .74+.03i |
| .53+.83i .34+.42i |
| .4+.49i .43+.39i |
| .51+.73i .19+.53i |
| .41+.23i .61+.02i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .66+1.5i .24+.33i |
| 1.2-.57i .24-.51i |
| -.16+.92i -.061+.25i |
| -.87-.68i .072+.49i |
| .39+1.6i 1.2+.26i |
| 1.4-.38i -.45-.52i |
| -.12+.11i .12-.26i |
| -.62+.38i .36+.2i |
| -.64-1.2i -.97-.8i |
| .38-1.7i -.11+.06i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.24126707662364e-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 = | .33 .9 .13 .28 .26 |
| .93 .77 .96 .72 .14 |
| .88 .61 .69 .15 .77 |
| .54 .28 .54 .28 .053 |
| .74 .12 .24 .51 .66 |
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 = | 2.2 -5.6 -1.5 11 1.2 |
| 1.2 -.21 .061 .23 -.53 |
| -2.4 3.9 1.7 -6.2 -1.4 |
| -.77 3.1 -.66 -4.9 .83 |
| -1.2 2.4 1.6 -6.1 .14 |
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 = 1.72084568816899e-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 = | 2.2 -5.6 -1.5 11 1.2 |
| 1.2 -.21 .061 .23 -.53 |
| -2.4 3.9 1.7 -6.2 -1.4 |
| -.77 3.1 -.66 -4.9 .83 |
| -1.2 2.4 1.6 -6.1 .14 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|