Matrix must be square error.

22 ビュー (過去 30 日間)
nanana sehaa
nanana sehaa 2017 年 9 月 27 日
回答済み: Walter Roberson 2017 年 9 月 27 日
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
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
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.

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by