MATLAB Answers

Why do I get "complex" arrays?

조회 수: 1(최근 30일)
Lujain Almarhabi
Lujain Almarhabi 2021년 5월 11일
댓글: Lujain Almarhabi 2021년 5월 11일
I am not supposed to get complex values but unfortunatley something is wrong in my eigenvalue caclultions. When plotting I get the error: (which I shouldn't be getting technically)
Warning: Imaginary parts of complex X and/or Y arguments ignored.
The part where the complex value show is in this specific line. However, everything above is a +ve number or value so I don't see how it turns complex:
r=q(1,:); % this is +ve when printed out
u=q(2,:)./r; E=q(3,:)./r;
Bx = q(4,:)./r; By = q(5,:)./r;
p=(gamma-1)*r.*(E-0.5*(u.^2)-(Bx.^2+By.^2)/(2*mu0)); % this is +ve
a=sqrt(gamma*p./r); % this is COMPLEX ???
CA1 = sqrt((Bx.^2+By.^2)./(r*mu0));
CAx1 = sqrt((Bx.^2)./(r*mu0));
a_MHD=sqrt(0.5*(CA1.^2+a.^2+sqrt((CA1.^2+a.^2).^2-4*a.^2.*CAx1.^2)));
I posted the entire code as well, main code is "MUSCLEULER_Test"

채택된 답변

Steven Lord
Steven Lord 2021년 5월 11일
If r contains only positive values and p contains only positive values, what about gamma?
areALLElementsOfRPositive = all(r > 0)
areALLElementsOfPNonnegative = all(p >= 0)
areALLElementsOfGammaNonnegative = all(gamma >= 0)
If any elements of r, p, or gamma would result in a complex value in the corresponding element of a, the array a will have the complex attribute.
  댓글 수: 4
Lujain Almarhabi
Lujain Almarhabi 2021년 5월 11일
Thanks!

댓글을 달려면 로그인하십시오.

추가 답변(0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by