I have ( An ) matrix, I need generalised algorithm to calculate An-1 = An *B. Here An-1, An, and B are matrices.
2 ビュー (過去 30 日間)
古いコメントを表示
sukumar nagineni
2018 年 10 月 18 日
コメント済み: sukumar nagineni
2018 年 10 月 19 日
For example, I have A3 matrix, such that i want to calculate matrices of A2, A1. A2= A3*B, A1=A2*B, here B is a matrix..... For matrix (An), I need generalised algorithm to calculate matrices An-1, An-2....A3, A2, A1, An-1=An*B, An-2= An-1*B .........A2=A1*B respectively.
1 件のコメント
Stephen23
2018 年 10 月 19 日
編集済み: Stephen23
2018 年 10 月 19 日
"I need generalised algorithm to calculate matrices An-1, An-2....A3, A2, A1, An-1=An*B, An-2= An-1*B .........A2=A1*B respectively"
Do NOT do this. Magically accessing variable names is one way that beginners force themselves into writing slow, complex, buggy code that is hard to debug. Read this to know why:
Learn to use arrays and indexing. Your problem will be much simpler and more efficient with one array (e.g. cell, ND numeric) and indexing.
採用された回答
John D'Errico
2018 年 10 月 18 日
You have A3, and you want to compute A2 and A1?
A2 = A3*B;
A1 = A2*B;
You want a general "algorithm"?
DON'T DO IT. Don't create numbered variables. That is just a bad idea. I know, you want to. DON'T DO IT.
Instead, learn to use multidimensional arrays. Or, learn to use cell arrays.
B = rand(3,3);
An = rand(3,3);
n = 10;
A = zeros(3,3,10);
A(:,:,n) = An;
for i = n-1:-1:1
A(:,:,i) = A(:,:,i+1)*B;
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および 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!