Matrix must be square error.
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi. Im trying to find determinant of A. But I got this type of error. How to solve this and why do I get this error?
This is my code:
function ret = detA(Ra)
global k
q0= 1i.*k.*(-1+(Ra./k^4)^(1/3))^(1/2);
q1= k.*(1+(Ra./k^4)^(1/3).*(1/2+1i*sqrt(3)/2))^(1/2);
q2= k.*(1+(Ra./k^4)^(1/3).*(1/2-1i*sqrt(3)/2))^(1/2);
A=[1 1 1 1 1 1;
exp(q0) exp(-q0) exp(q1) exp(-q1) exp(q2) exp(-q2);
q0 -q0 q1 -q1 q2 -q2;
q0.*exp(q0) -q0.*exp(-q0) q1.*exp(q1) -q1.*exp(-q1) q2.*exp(q2) -q2.*exp(-q2);
(q0.^2-k.^2).^2 (q0^2-k^2).^2 (q1^2-k^2).^2 (q1^2-k^2).^2 (q2^2-k^2)^2 (q2^2-k^2)^2;
(q0.^2-k.^2).^2.*exp(q0) (q0^2-k^2).^2.*exp(-q0) (q1^2-k^2).^2.*exp(q1) (q1^2-k^2).^2.*exp(-q1) (q2^2-k^2).^2.*exp(q2) (q2^2-k^2).^2.*exp(-q2)];
ret=det(A);
end
And i got this error:
Error using det
Matrix must be square.
Error in detA (line 14)
ret=det(A);
Try Ra=1708.
1 comentario
KSSV
el 27 de Sept. de 2017
You should note that determinant exists for a square matrix only. For rectangular matrices, vectors you cannot find determinant. In your case when Ra = 1708..your A is a vector of size 1x6. So determinant does not exist for this..so error.
Respuestas (1)
Walter Roberson
el 27 de Sept. de 2017
You did not initialize the global variable k. Uninitialized global variables are empty. Your q are calculated from k so they are empty.
0 comentarios
Ver también
Categorías
Más información sobre Linear Algebra en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!