(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 = | .87+.55i .36+.29i .88+.77i .23+.5i .87+.98i .17+.45i .7+.96i
| .75+.38i .95+.86i .73+.81i .2+.3i .54+.45i .76+.56i .12+.33i
| .31+.82i .44+.54i .98+.91i .57+.46i .78+.81i .86+.97i .47+.72i
| .43+.29i .78+.75i .65+.25i .6+.79i .01+.79i .94+.94i .68+.73i
| .5+.66i .63+.94i .24+.84i .29+.38i .16+.31i .08+.98i .55+.92i
| .27+.55i .26+.65i .3+.77i .89+.2i .92+.5i .82+.82i .5+.16i
| .32+.81i .51+.46i .15+.33i .56+.34i .09+.98i .072+.014i .83+.6i
| .04+.71i .31+.32i .23+.23i .77+.84i .33+.33i .5+.44i .95+.59i
| .67+.96i .57+.32i .93+.07i .25+.27i .033+.26i .63+.78i .11+.1i
| .4+.59i .85+.85i .28+.78i .69+.98i .014+.24i .42+.42i .02+.95i
-----------------------------------------------------------------------
.32i .02+.58i .53+.52i |
.35+.42i .37+.42i .82+.06i |
.82+.15i .24+.13i .86+.56i |
.4+.89i .01+.65i .26+.14i |
.95+.88i .3+.61i .79+.58i |
.19+.089i .3+i .54+.33i |
.88+.2i .3+.71i .88+.62i |
1+.42i .79+.82i .45+.71i |
.59+.71i .37+.53i .99+.11i |
.11+.94i .79+.53i .85+.19i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .65+.69i .69+.65i |
| .048+.17i .44+.97i |
| .34+.89i .37+.92i |
| .08+.53i .34+.34i |
| .78+.72i .49+.59i |
| .59+.15i .81+.84i |
| .11+.32i .71+.94i |
| .36+.86i .76+.44i |
| .17+.68i .41+.6i |
| .59+.14i .25+.42i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | 1.1+.36i .1+.12i |
| .26+1.7i .85-1.1i |
| -1.8-.17i 1.4+1.4i |
| .016+.17i .89+.65i |
| -.03+.93i .12-.013i |
| 1.2-.74i -1.5-.57i |
| .5-.76i -.89-.75i |
| -.79-.09i .18+1.6i |
| -.55+.33i .96-1.1i |
| 1.4-1.2i -1.1-.42i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 1.48952049194836e-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 = | .79 .4 .7 .87 .016 |
| .41 .22 .023 .95 .6 |
| .83 1 .93 .083 .11 |
| .01 .83 .42 .33 .32 |
| .63 .099 .98 .15 .48 |
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 = | -.45 .94 1.5 -1.7 -.34 |
| -.32 .17 .75 .5 -.7 |
| .82 -1.2 -.97 .95 .99 |
| 1.1 -.034 -.9 .58 -.17 |
| -1.3 1.1 .2 .048 .72 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 4.44089209850063e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 3.88578058618805e-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 = | -.45 .94 1.5 -1.7 -.34 |
| -.32 .17 .75 .5 -.7 |
| .82 -1.2 -.97 .95 .99 |
| 1.1 -.034 -.9 .58 -.17 |
| -1.3 1.1 .2 .048 .72 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|