Attempt to have a 3D mesh plot of max value of real part of eigenvalues of a matrix. Shows error saying that 'Error showing Horzcat. CAT arguments dimensions are not consistent' even though my matrix is square.

1 view (last 30 days)
Bilbo Baggins
Bilbo Baggins on 27 Apr 2012
Answered: VBBV on 22 Nov 2021
Here is my code:
[B,k]=meshgrid(0:0.01:10);
BKm= [0, 1, 0, 0, 0, 0;
(-0.0517428 *k-0.444277), (-0.260491), (0.112669 *k+0.135935), (0.711674), (-0.12895 *k-1.63146), (-0.711674);
0, 0, 0, 1, 0, 0;
(0.141364 *k+1.21379), (0.711674), (0.0374225-0.294178 *k), (-1.94433), (0.325021 *k+3.63963), (1.94433);
0, 0, 0, 0, 0, 1;
(-0.141364 *k-1.21379), (-0.711674), (0.270554 *k-0.745489), (1.94433), (-0.301397 *k-2.93156), (-1.94433)
];
EV=eig(BKm);
Eigmax=max(real(EV));
surf(k,B,BKm)
And the error:
Error using horzcat
CAT arguments dimensions are not consistent.
I am attempting to plot the maximum of real parts of all eigenvalues available for this matrix in a 3D contour sort of plot. Even though my matrix seems square to me, I am getting this error. Please help. Thanks in advance.

Answers (3)

Kye Taylor
Kye Taylor on 27 Apr 2012
When you create BKm, you use the output k from meshgrid. The output k is a 1001 square matrix that you are effectively trying to use as a scalar in the definition of BKm.
If k were a scalar, BKm would be a 6-by-6 square matrix so the surf command won't work unless BKm is the same size as k, which must also be the same size as B in order for surf() to work.

Walter Roberson
Walter Roberson on 27 Apr 2012
k is 1001 by 1001. a*k+b with a and b scalar would then be 1001 x 1001. You then try to horzcat a 1 x 1 scalar -0.260491 with that (second line of matrix). Dimension problems.
What are you trying to do, create a 4D matrix, 6 x 6 x 1001 x 1001 ? If you do, you will not be able to eig() that matrix.

VBBV
VBBV on 22 Nov 2021
[B,k]=meshgrid(linspace(0,10,1))
B = 10
k = 10
BKm= [0, 1, 0, 0, 0, 0;
(-0.0517428 *k-0.444277), (-0.260491), (0.112669 *k+0.135935), (0.711674), (-0.12895 *k-1.63146), (-0.711674);
0, 0, 0, 1, 0, 0;
(0.141364 *k+1.21379), (0.711674), (0.0374225-0.294178 *k), (-1.94433), (0.325021 *k+3.63963), (1.94433);
0, 0, 0, 0, 0, 1;
(-0.141364 *k-1.21379), (-0.711674), (0.270554 *k-0.745489), (1.94433), (-0.301397 *k-2.93156), (-1.94433)
]
BKm = 6×6
0 1.0000 0 0 0 0 -0.9617 -0.2605 1.2626 0.7117 -2.9210 -0.7117 0 0 0 1.0000 0 0 2.6274 0.7117 -2.9044 -1.9443 6.8898 1.9443 0 0 0 0 0 1.0000 -2.6274 -0.7117 1.9601 1.9443 -5.9455 -1.9443
EV=eig(BKm);
Eigmax=max(real(EV));
surfc(BKm)
Try this

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!