Matrix must be square error.

22 visualizaciones (últimos 30 días)
nanana sehaa
nanana sehaa el 27 de Sept. de 2017
Respondida: Walter Roberson el 27 de Sept. de 2017
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
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.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
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.

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!

Translated by