using imaginary notation gives an error (-J)
Mostrar comentarios más antiguos
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
5 comentarios
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
hace 4 minutos
dpb
hace 34 minutos
Guessing (again, w/o code or error messages, it's crystal ball time; most everybody inferred what the issue probably was this time, but that's not always going to happen), probably it is a script and not a function and somebody wanted a different signal so created q1 at the command line before running the code after commenting out the one inside the script.
How's that for a guess? <grin>
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!