- #1
gfd43tg
Gold Member
- 950
- 50
Homework Statement
In this problem, you will write code that computes the Kronecker product of two arrays. Suppose
A is a numeric array of size r-by-c and B is a numeric array of size n-by-m. Then the Kronecker
product of A with B is a numeric array, of dimension rn-by-cm, defined as:
Homework Equations
The Attempt at a Solution
Code:
A = [1 2; 3 4];
B = [1 10 100];
Here is my code and result
Code:
C = zeros(length(A),length(B)*length(A));
for i = 1:length(A)
for j = 1:length(C)
C(i,1:3) = A(i)*B
end
end
Code:
C =
1 10 100 0 0 0
3 30 300 0 0 0
I cannot for the life of my figure out how to add onto columns 4-6 for this array. It seems like my for loop with j doesn't do anything, and everytime I mess with my columns I get mismatch dimension errors.
C should look like this
Code:
C =
1 10 100 2 20 200
3 30 300 4 40 400
I am able to construct this array in the command window, but I cannot generalize to get it working with my loops. I want to take the code I just did here and incorporate it into my loops, but it is proving to be very difficult.
Code:
zeros(length(A),length(B)*length(A))
ans =
0 0 0 0 0 0
0 0 0 0 0 0
EDU>> C(1,1:3) = A(1)*B;
EDU>> C(2,1:3) = A(2)*B;
EDU>> C(1,4:6) = A(3)*B;
EDU>> C(2,4:6) = A(4)*B;
EDU>> C
C =
1 10 100 2 20 200
3 30 300 4 40 400