Matrix must be square error.

22 views (last 30 days)
nanana sehaa
nanana sehaa on 27 Sep 2017
Answered: Walter Roberson on 27 Sep 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 Comment
KSSV
KSSV on 27 Sep 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.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 27 Sep 2017
You did not initialize the global variable k. Uninitialized global variables are empty. Your q are calculated from k so they are empty.

Categories

Find more on Linear Algebra 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!