Matrix must be square error.
조회 수: 22 (최근 30일)
이전 댓글 표시
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
KSSV
2017년 9월 27일
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.
답변 (1개)
Walter Roberson
2017년 9월 27일
You did not initialize the global variable k. Uninitialized global variables are empty. Your q are calculated from k so they are empty.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!