How to read elements from a computed matrix without define a new variable?
古いコメントを表示
Dear all,
I am having a question about matrix computation. For example, a matrix A is calculated by an expression,
. I am only interested in the element
. Simply I can do
and
. I am wondering whether there is a way to do this without defining A. This line of code is not legal in MATLAB but it shows my goal clearly,
.
. I am only interested in the element
and
. I am wondering whether there is a way to do this without defining A. This line of code is not legal in MATLAB but it shows my goal clearly,
. Thanks!
7 件のコメント
gonzalo Mier
2019 年 5 月 10 日
This feature was asked for future versions, but the answer of the staff was for that you need to create the variable anyways, so you are only losing legilability, not wining performance.
Mathematically, you can just compute the first element as
a = exp(B(1,:)*C(:,1)+D(1));
Torsten
2019 年 5 月 10 日
Of course,
a = exp(B(1,:)*C(:,1)+D(1));
is wrong in general.
It's true if, e.g., B*C+D is a diagonal matrix.
gonzalo Mier
2019 年 5 月 10 日
編集済み: gonzalo Mier
2019 年 5 月 10 日
Eeeeeemmmm, Torsten... this equation is true always...
If you want to check:
A = rand(3);B = rand(3); C = A*B; D = A(1,:)*B(:,1); D==C(1,1)
Torsten
2019 年 5 月 10 日
The matrix exponential of a matrix is not equal to the matrix where all of its elements are "exponentialized".
gonzalo Mier
2019 年 5 月 10 日
Yize Wang, this is the easiest way and fastest to do it as I know. If you are concern about legibility, you can encapsulate this piece of code in a function called get_1_comp_system or some cool name (I'm not good at all naming).
"Eeeeeemmmm, Torsten... this equation is true always..."
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!