矩阵运算
- 输入矩阵
可以用entermatrix(m,n)输入一个m乘n矩阵。如果m=n,Maxima会自动询问是什么类型的矩阵,以减少输入的工作量。
(%i1) m: entermatrix(2,2);
Is the matrix 1. Diagonal 2. Symmetric 3. Antisymmetric 4. General
Answer 1, 2, 3 or 4 :
4;
Row 1 Column 1:
a;
Row 1 Column 2:
1;
Row 2 Column 1:
0;
Row 2 Column 2:
b;
Matrix entered.
[ a 1 ]
(%o1) [ ]
[ 0 b ]
也可以用matrix以行为单位输入(%i2) matrix([a,b,c],[1,2,3],[d,e,f]);
[ a b c ]
[ ]
(%o2) [ 1 2 3 ]
[ ]
[ d e f ]
- 矩阵的转置,逆和行列式
(%i3) transpose(m);
[ a 0 ]
(%o3) [ ]
[ 1 b ]
(%i4) invert(m);
[ 1 1 ]
[ - - --- ]
[ a a b ]
(%o4) [ ]
[ 1 ]
[ 0 - ]
[ b ]
(%i5) determinant(m);
(%o5) a b
- 矩阵的代数运算
(%i6) m . %o4;
[ 1 0 ]
(%o6) [ ]
[ 0 1 ]
(%i7) %o6 + %o4;
[ 1 1 ]
[ - + 1 - --- ]
[ a a b ]
(%o7) [ ]
[ 1 ]
[ 0 - + 1 ]
[ b ]
- 提取矩阵的某一行或某一列
(%i8) row(m,1);
(%o8) [ a 1 ]
(%i9) col(%o7,2);
[ 1 ]
[ - --- ]
[ a b ]
(%o9) [ ]
[ 1 ]
[ - + 1 ]
[ b ]
- 为矩阵增加一行(列)或几行(列)
(%i10) addcol(m,[0,1],[c,1]);
[ a 1 0 c ]
(%o10) [ ]
[ 0 b 1 1 ]
(%i11) addrow(%o10,[1,0,0,1]);
[ a 1 0 c ]
[ ]
(%o11) [ 0 b 1 1 ]
[ ]
[ 1 0 0 1 ]
- 另外,+, -, *, /, ^, exp(x)等运算都可以应用于矩阵,这些运算符分别作用于每一个元素。
(%i12) m/c;
[ a 1 ]
[ - - ]
[ c c ]
(%o12) [ ]
[ b ]
[ 0 - ]
[ c ]