(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 = | .6+.78i .77+.78i .78+.13i .73+.04i .22+.18i .9+.9i .24+.23i
| .23+.35i .28+.61i .59+.99i .33+.41i .49+.21i .18+.14i .43+.71i
| .42+.21i .42+.95i .53+.07i .13+.05i .41+.52i .05+.55i .88+.56i
| .47+.47i .49+.27i .48+.13i .54+.47i .96+.76i .92+.18i .17+.41i
| .81+.18i .53+.99i .69+.75i .03+.8i .34+.76i .83+.78i .87+.59i
| .33+.69i .91+.74i .44+.72i .08+.59i .22+.36i .094+.31i .09+.95i
| .19+.1i .38+.002i .31+.32i .18+.25i .45+.59i .8+.57i .96+.45i
| .44+.42i .65+.04i .15+.27i .84+.11i .12+.42i .42+.1i .097+.012i
| .03+.66i .68+.38i .56+.23i .33+.23i .43+.16i .17+.51i .1+.68i
| .6+.19i .48+.71i .18+.59i .26+.81i .19+.28i .49+.53i .26+.61i
-----------------------------------------------------------------------
.75+.49i .22+.45i .77+.39i |
.93+.98i .54+.3i .3+.44i |
.5+.48i .31+.57i .49+.22i |
.89+.8i .34+.085i .74+.88i |
.3+.72i .17+.069i .054+.38i |
.67+.57i .88+.71i .49+.45i |
.95+.19i .71+.63i .85+.92i |
.07+.75i .93+.53i .67+.13i |
.88+.38i .56+.68i .08+.76i |
.7+.77i .88+.76i .06+.6i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .38+.93i .77+.81i |
| .4+.97i .75+.27i |
| .88+.2i .34+.72i |
| .26+.79i .09+.83i |
| .085+.032i .87+.92i |
| .83+.8i .23+.19i |
| .08+.79i .36+.66i |
| .015+.39i .62+.74i |
| .23+.78i .42+.17i |
| .66+.63i .0076+.024i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | -.59-.33i .97+.04i |
| -.32-.75i .32+.35i |
| -.12+1.6i .85-1.8i |
| -.11-.85i -.3+1.5i |
| -1+.16i 1.4+.37i |
| .29+.59i .14-.11i |
| .43-.91i -.06+.74i |
| .85-.49i -.85+.35i |
| .61+.44i -.17-.84i |
| .32+.93i -.38-.29i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.51006657275581e-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 = | .76 .19 .73 .49 .91 |
| .75 .19 .29 .54 .74 |
| .37 .51 .56 .73 .5 |
| .092 .43 .85 .09 .72 |
| .57 .11 .86 .071 .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 = | -5.2 3.6 .64 -.99 3.7 |
| -8.5 5.4 1.3 1.4 3.2 |
| 1.8 -2.7 .81 -.73 .77 |
| 5.2 -3.5 .84 -1 -2.7 |
| 3 -.055 -1.9 1.7 -2.9 |
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.77635683940025e-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 = | -5.2 3.6 .64 -.99 3.7 |
| -8.5 5.4 1.3 1.4 3.2 |
| 1.8 -2.7 .81 -.73 .77 |
| 5.2 -3.5 .84 -1 -2.7 |
| 3 -.055 -1.9 1.7 -2.9 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|