Why does kron(D,I), with D and I both sized (nxn), not create a matrix sized (n^2 x n^2)?
1 view (last 30 days)
Show older comments
I am trying to run a code that involves operating on the elements of a matrix made by a kronecker sum operation, but I meet a sub2ind error. I have found that the problem is that MATLAB doesn't generate the matrix size it is supposed to generate after one kind of kronecker product operation in particular:
x = sym('x', [1 15], 'real')
I = eye(5)
D = diag(-x(1) -x(2) -x(3) -x(4) -x(5))
disp(kron(I,D))
Which causes an error in my code that involves the following:
DsumD = kron(D,I) + kron(I,D)
zeta = sym(zeros(1,25));
for i = 1:25
zeta(1,i) = -DsumD(i,i);
end
zetatopi = sym(zeros(1,25));
for j = 1:25
zetatopi(1,i) = log(1+zeta(1,i)*x(15))/x(15);
end
DsumDtopi = diag(-zetatopi)
Does anyone know how I can make MATLAB do the kronecker operations properly?
0 Comments
Accepted Answer
Paul
on 14 Dec 2021
Because D is not 5 x 5
x = sym('x', [1 15], 'real');
D = diag(-x(1) -x(2) -x(3) -x(4) -x(5))
size(D)
Perhaps you meant
D = diag(x(1:5))
or
D = diag([-x(1) -x(2) -x(3) -x(4) -x(5)])
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!