# Easier method to iterative matrix multiplication?

5 views (last 30 days)
arthurk on 25 Feb 2020
Answered: Matt J on 25 Feb 2020
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

Bjorn Gustavsson on 25 Feb 2020
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 on 25 Feb 2020
Apologies, terrible question. I will explain it better

Matt J on 25 Feb 2020
No, a loop is the best way.