フィルターのクリア

how to preferentially compute vector products rather than matrix products

1 回表示 (過去 30 日間)
Lee Jong Hyun
Lee Jong Hyun 2023 年 8 月 1 日
編集済み: Lee Jong Hyun 2023 年 8 月 1 日
When performing a multiplication operation between a matrix and a vector, it seems that MATLAB's default settings are to be executed from the left.
This method has a problem in that calculation time is too long when complex multi-term matrix operations are performed.
Is there any way to change this setting without bracket?
For instance, how to preferentially compute vector products rather than matrix products.
Please, let me know.
N = 5000;
A = rand(N);
B = rand(N);
C = rand(N);
D = rand(N,1);
tic
E1 = A*B*C*D;
toc
tic
E2 = A*(B*(C*D));
toc

採用された回答

Matt J
Matt J 2023 年 8 月 1 日
編集済み: Matt J 2023 年 8 月 1 日
Is there any way to change this setting without bracket?
I doubt there is, but it's the kind of thing that should probably be handled using a user-defined function anyway, rather than a Matlab environment change. This FEX submission for example attempts to implement matrix products in an optimized order, shielding the user from the details:

その他の回答 (1 件)

Paul
Paul 2023 年 8 月 1 日
"Is there any way to change this setting without bracket?"
No. From the doc page for Operator Precedence: "Within each precedence level, operators have equal precedence and are evaluated from left to right."
However, that statement should say "... most are evaluated ..." as that page show exceptions to the general rule. But mtimes, * is not one of those exceptions.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by