MATLAB Answers

Spacing in defining complex numbers?

조회 수: 3(최근 30일)
Knut
Knut 8 May 2017
답변: Guillaume 8 May 2017
I just spent a while puzzling over a problem until it dawned on me:
a1 = [3.98994e-05 +1i*-0, 4.21732e-05 +1i*3.69849e-05];
Computes to :
1.0e-04 *
0.3990 + 0.0000i 0.0000 + 0.0000i 0.4217 + 0.0000i 0.0000 + 0.3698i
To get what I expected, I had to do the following (strip spaces):
[3.98994e-05+1i*-0, 4.21732e-05+1i*3.69849e-05]
1.0e-04 *
0.3990 + 0.0000i 0.4217 + 0.3698i
I am debugging a large vector written from C code, so my hunch was to spend quite some time looking for bugs in C-code before starting to look at the numerical interpretation in MATLAB.
-k

  댓글 수: 0

로그인 to comment.

답변(2개)

KSSV
KSSV 8 May 2017
You can try braces instead of space..
a1 = [(3.98994e-05 +1i*-0), (4.21732e-05 +1i*3.69849e-05)];

  댓글 수: 0

로그인 to comment.


Guillaume
Guillaume 8 May 2017
The whole reason for this is that you're not consistent with your spacing around the operators. Either put a space before and after the +, or none on either side. As it is, because of the space before and none after, the + is interpreted as the unary +.

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

제품


Translated by