using imaginary notation gives an error (-J)
이전 댓글 표시
Hi,
I am fairly new to matlab but used it years ago and have forgotten a lot.
I have downloaded an m file which should work but provides an error when encountering the following line of code.
u2=-J*u2.*q1; and there are two carrots underneath the "q1".
Can someone provide a suggestion as to how to interpret this error?
Thank You
Tom
댓글 수: 4
The imaginary unit is i, j, 1i, or 1j, not J:
-i
-j
-J
"Can someone provide a suggestion as to how to interpret this error"
You did not give us any error message, so interpreting it is a challenge. My guess is some size or type mismatch. The carets indicate its likely location.
What does the error message say?
From the perspective of the person who wrote the original code, why would they choose to upload an m-file online that does not work in the first place?
Moreover, for anyone already familiar with how imaginary numbers work in MATLAB, if j is intended to represent the imaginary unit, it seems very strange to write -j*u2.*q1 instead of using the conventional form -u2.*q1*1j, which avoids any potential ambiguity of j.
Finally, is the m-file a helper function that expects J to be computed beforehand or properly initialized? After all, the expression u2 = -J*u2.*q1 may indicate that u2 is being computed iteratively.
J = asin(2)
u2 = 1;
q1 = 3;
u2 = -J*u2.*q1
I think the subject line of the Q? about complex numbers plus the fact the interpreter indicated it failed on the variable q1 a misinterpretation of the error here; as @Stephen23 notes, the builtin imaginary variable functions are lower case, not upper, so the J in "-J" is NOT sqrt(-1) unless J has previously been defined in the m-file to have aliased it (or it's a script, not a function and the same has been done in the workspace).. I would venture the likelihood of either of those is quite low.
Instead, it's highly likely it is q1 that isn't defined, but as others have noted, without the error message in context to see, it's all purely conjecture. Showing us the code itself would also likely have allowed to see what might be wrong.
Tom Cipollone
대략 4시간 전
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!