(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 = | .17+.55i .69+.13i .64+.1i .98+.59i .35+.7i .13+.83i .018+.28i
| .16+.39i .28+.66i .31+.53i .95+.73i .16+.77i .23+.45i .56+.38i
| .28+.27i .77+.96i .7+.35i .81+.53i .66+.22i .21+.92i .02+.71i
| .08+.98i .6+.59i .29+.85i .55+.87i .068+.31i .6+.34i .67+.67i
| .4+.18i .16+.52i .082+.38i .75+.08i .1+.18i .81+.93i .32+.88i
| .43+.35i .45+.55i .4+.64i .89+.65i .22+.1i .14+.26i .013+.45i
| .71+.09i .49+.6i .61+.81i .33+.19i .54+.67i .93+.64i .89+.28i
| .75+.02i .18+.93i .83+.22i .46+.039i .52+.26i .39+.13i .045+.44i
| .15+.51i .74+.37i .34+.25i .25+.57i .5+.49i .23+.35i .3+.71i
| .39+.75i .27+.59i .019+.3i .55+.32i .92+.05i 1+.29i .24+.21i
-----------------------------------------------------------------------
.59+.76i .11+.47i .31+.87i |
.03+.9i .62+.42i .5+.84i |
.19+.7i .62+.1i .32+.87i |
.56+.12i .63+.72i .98+.56i |
.27+.052i .88+.7i .91+.79i |
.03+.94i .6+.31i .15+.72i |
.32+.48i .56+.53i .03+.98i |
.87+.12i .38+.4i .35+.006i |
.11+.21i .39+.57i .57+.34i |
.42+.76i .53+.38i .86+.99i |
10 10
o13 : Matrix CC <--- CC
53 53
|
i14 : b = random(CC^n,CC^2)
o14 = | .56+.33i .25+.07i |
| .78+.64i .42+.35i |
| .24+.045i .4+.95i |
| .96+.48i .072+.27i |
| .8+.46i .74+.6i |
| .53+.33i .69+.16i |
| .87+.58i .52+.31i |
| .62+.47i .85+.13i |
| .25+.16i .95+.58i |
| .74+.43i .49+.52i |
10 2
o14 : Matrix CC <--- CC
53 53
|
i15 : x = solve(A,b)
o15 = | .025-.081i .011+.23i |
| .49-.36i .59-.36i |
| -.48+.27i 1+.77i |
| -.073+.082i -.55+1.1i |
| -.59-.31i -.33+i |
| .15+.12i .045-.31i |
| -.08+.79i .44+.21i |
| .7-.11i -1.1-1.9i |
| 1.2-.53i -.06-2.6i |
| -.25-.072i .64+1.2i |
10 2
o15 : Matrix CC <--- CC
53 53
|
i16 : norm ( matrix A * matrix x - matrix b )
o16 = 7.85046229341888e-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 = | .94 .58 .6 .099 .74 |
| .85 .7 .74 .13 .47 |
| .11 .68 .08 .37 .53 |
| .12 .26 .4 .86 .31 |
| .0045 .53 .74 .0091 .65 |
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 = | .86 .26 -.27 -.0094 -.93 |
| -1.9 2 1.5 -.73 -.2 |
| -.7 .87 -1.2 .47 .93 |
| -.042 -.12 .096 1.2 -.49 |
| 2.3 -2.6 .15 .049 .66 |
5 5
o19 : Matrix RR <--- RR
53 53
|
i20 : norm(A*A' - I)
o20 = 6.66133814775094e-16
o20 : RR (of precision 53)
|
i21 : norm(A'*A - I)
o21 = 6.66133814775094e-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 = | .86 .26 -.27 -.0094 -.93 |
| -1.9 2 1.5 -.73 -.2 |
| -.7 .87 -1.2 .47 .93 |
| -.042 -.12 .096 1.2 -.49 |
| 2.3 -2.6 .15 .049 .66 |
5 5
o22 : Matrix RR <--- RR
53 53
|
i23 : norm(A' - A'')
o23 = 0
o23 : RR (of precision 53)
|