Easier method to iterative matrix multiplication?
이전 댓글 표시
n = 10
matrix = zeros(n,n);
matrix(1,1:n) = 2
matrix1 = zeros(n,n);
matrix1(1:n,1) = 4
for i = (1:n)
matrix(i+1,1:n) = matrix(i,1:n)*matrix1;
end
matrix
Outputs:
matrix =
2 2 2 2 2 2 2 2 2 2
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
matrix1 =
4 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
matrix =
2 2 2 2 2 2 2 2 2 2
80 0 0 0 0 0 0 0 0 0
320 0 0 0 0 0 0 0 0 0
1280 0 0 0 0 0 0 0 0 0
5120 0 0 0 0 0 0 0 0 0
20480 0 0 0 0 0 0 0 0 0
81920 0 0 0 0 0 0 0 0 0
327680 0 0 0 0 0 0 0 0 0
1310720 0 0 0 0 0 0 0 0 0
5242880 0 0 0 0 0 0 0 0 0
20971520 0 0 0 0 0 0 0 0 0
The point is that matrix will have more values added to it. matrix 1 will be filled with many different values. I'm trying to find an easier way than a for loop.
matrix1 is made to be that way for easier explanation
댓글 수: 2
Bjorn Gustavsson
2020년 2월 25일
Looks a bit strange. matrix(i+1,1:n) will be an [1 x n] array, on the right-hand-side matrix(i,1:n) will have the same size. That will force matrix1 to be a scalar for matrix-multiplication to work. Perhaps you want elementwise multiplication? Or some slightly different operation?
arthurk
2020년 2월 25일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Spline Postprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!