访问 Maxima 矩阵图中的 i 和 j 变量?
我仍然是一个 maxima 新手,所以请耐心等待。我正在尝试编写自己的公式来计算矩阵的伴随(我知道 maxima 已经有一个内置公式,但我正在尝试自己的公式作为学习练习)。到目前为止我已经(对于 3x3 矩阵):
/* cofactor of some submatrix of the matrix, by deleting row i and column j */
cof(i, j, M) := determinant(submatrix(i, M, j));
/* for 3 x 3 matrix */
C3(M) := matrix( [cof(1,1,M), cof(1,2,M), cof(1,3)],
[cof(2,1,M), cof(2,2,M), cof(2,3)],
[cof(3,1,M), cof(3,2,M), cof(3,3)] );
/* function for calculating adjoint sign for x at position i, j */
adj_f(i, j, x) := -1^(i+j) * x;
/* adjugate for a 3x3 matrix M */
adj3(M) := matrixmap(lambda([i,j,x], adj_f(i,j,x), transpose(C3(M))));
我知道这可能不是最好的方法;但是,我想知道使用 MatrixMap 或 FullMapl 时是否有一种方法可以访问 i 和 j 元素?
(我正在使用 wxMaxima 并且我没有太多的 lisp 经验,我试图在不接触任何代码的情况下摆脱这个问题)。
I'm still a maxima newbie so bear with me. I am trying to write my own formula for calculating the adjoint of a matrix (I know maxima already has one built-in, but I was trying my own as a learning exercise). So far I have (for a 3x3 matrix):
/* cofactor of some submatrix of the matrix, by deleting row i and column j */
cof(i, j, M) := determinant(submatrix(i, M, j));
/* for 3 x 3 matrix */
C3(M) := matrix( [cof(1,1,M), cof(1,2,M), cof(1,3)],
[cof(2,1,M), cof(2,2,M), cof(2,3)],
[cof(3,1,M), cof(3,2,M), cof(3,3)] );
/* function for calculating adjoint sign for x at position i, j */
adj_f(i, j, x) := -1^(i+j) * x;
/* adjugate for a 3x3 matrix M */
adj3(M) := matrixmap(lambda([i,j,x], adj_f(i,j,x), transpose(C3(M))));
I know this probably isn't the best way of doing it; however, I was wondering if there was a way of accessing the i and j elements when using matrixmap or fullmapl?
(I'm using wxMaxima and I don't have a whole lot of lisp experience, I was trying to get away with this without touching any code).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,你不能用矩阵映射来做到这一点
,因为 i 和 j 不是 M 的第 (i,j) 个元素的函数。
命令式解决方案可能如下所示:
请注意,你的 C3 函数缺少一些“M” 's 和 adj_f 必须为
(否则对于所有 i,j 都是 -( (1)^(i+j) ) = -1)。
Well, you can't do it with matrixmap
since i and j are not functions of the (i,j)-th element of M.
An imperative solution might look like the following:
Note that your C3 function was missing some "M"'s and adj_f needs to be
(otherwise it's -( (1)^(i+j) ) = -1 for all i,j).
尝试使用 genmatrix 而不是矩阵图。 genmatrix 的第一个参数是一个以 i 和 j 作为参数的函数。
抱歉回复晚了。将其留在这里,以防有人通过搜索找到它。
Try genmatrix instead of matrixmap. First argument of genmatrix is a function which takes i and j as arguments.
Sorry for the late reply. Leaving this here in case someone finds it by searching.