質問

変数に保存されているマトリックスのリストがあるとします G 次の操作を適用します。

top[g_] = Minors[g]
Diagonal[top /@ G] 

Minors各要素が(i、j)row/colが削除された決定要因であるマトリックスを返し、 Diagonal マトリックスの対角線要素のリストを返します。

私の質問は、これらのコマンドの評価に関するものです - 明らかに、すべてのエントリが評価されたくないことです。 Mathematicaは、斜めが最初に解析され、未成年者から必要な要素のみを抽出するか、マイナーマトリックスが構築され、その斜めの要素が引き出されるという意味で怠zyされていますか?

これは怠zyな評価の一般的な質問ですが、Mathematicaにとって新しいことですが、特定の問題の構文を改善する方法についてのヒントをお勧めします。

役に立ちましたか?

解決

遅れているので、短い答えだけです:調査する Hold[] そしてその親relative。それらを使用すると、怠zyな評価機能を実装できます。ほとんどの本質的な数学機能は怠zyではありません。一般に、初心者として、Mathematicaの本質的な機能の動作を変更することは避けてください。

他のヒント

You can solve this problem by building up the list of diagonal minors by yourself and then applying Det, for a matrix M:

Map[Det,Drop[Transpose[Drop[M,{#}]],{#}]& /@ Range[1,Dimensions[M][[1]]]]

This is a bit of a cludge but it is about 50 times faster than using Mathematica's built in Minors and picking off just the diagonal elements (tested on 100x100 random matrices).

No mathematica is not lazy in general.

top/@G 

Will produce a matrix that Diagonal will operate on. Since Minors does not operate on individual elements of the matrix, what you are asking for is not, from my knowledge, just lazy evaluation either.

I think I have a solution for you though.

Clear[f];
Diagonal[Minors[G,Length[G],f]]/.f->Det

This solution will only produce the Minors of the Diagonal elements to be summed by Diagonal. But I have only moved the excess computation to an excess memory usage problem. Since the submatrix of off diagonal elements is still produced only to be thrown away. I will post again if I think of a way to prevent that as well.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top