Bug in symbolic toolbox?

Hi all, I am experiencing a strange behavior of the sym function. The result of sym('I') is 'I'. While the result of sym('A+I') is 'A+i' with an unwanted lower case letter of 'I'.
Has anyone experienced such a behavior? Is it a bug? and if so is there any workaround?
Thanks, Junior

 Accepted Answer

In the input regions MuPAD recognizes an uppercase I as the imaginary unit (-1)^(1/2). In the output regions, MuPAD uses a lowercase i to display the imaginary unit
I – imaginary unit sqrt(-1) (see DOM_COMPLEX for details)
Complex numbers can be constructed by typing in the corresponding expression, such as 3+4*I. The keyword for typing the imaginary unit I is I (a capital letter i).
Thus, what you are seeing is not a bug.
I know that in Maple it is possible to change the representation letter, but I do not at the moment see any corresponding mechanism in MuPad. (In Maple, it would be by using interface(imaginaryunit=SYMBOL) )

1 Comment

Junior
Junior on 19 Aug 2011
Thanks Walter for enlightening me on this matter. The conclusion then is that mupad and standard matlab differ in this respect. For me, the imaginary unit was "i" and not "I".

Sign in to comment.

More Answers (1)

It's seeing I as the sqrt(-1). What is your goal by doing it this way?
why not just
syms A I
A+I
?
The other easiest workaround would just be to use a different letter, J, or II.
sym('A+II')

5 Comments

Junior
Junior on 18 Aug 2011
Sean, thanks for the answer. I discovered the bug as I was trying to compare numerical to symbolic derivatives on a system of equations. My code parses a dynamic system written in a text file and then computes a Taylor expansion of the system.
I thought about the workarounds you suggested long before I posted the question. But this is not a robust solution to my problem. The systems I deal with can have more than 1000 equations and I do not have control over the list of the variables a priori. Everything is done automatically. the simple example I provided is just to replicate the bug.
Something else I thought about, was to write a function that checks whether there is a variable with name 'I' and if there is, replace it with an auxiliary variable. So that when the derivatives are computed the function would do the inverse operation. But this does not seem to be the first best solution.
Junior
P.S: by the way, sym('A+J') gives the correct result but not sym('A+I')
Well the effect you're seeing is the same reason we don't like to "poof" variables with eval or assignin because those variables could have other meanings.
eval([input('enter a string','s') '= 17']); %enter>> sum
etc. It should be simple enough to do a find and replace on every i, replace it with some long hex expression unlikely to be repeated. Or come up with a way to do the expansion through indexing, this isn't my area of expertise but I'm sure there's method.
I don't see that "bug" on my MATLAB 2008b sym('I') gives I, try this:
reset(symengine)
Paulo: sym('A+I')
MuPad allows variable names that are not valid MATLAB variable names, so as long as you are processing at the MuPAD level, you could, for example, replace I by _I and strip off the underscore later.
Or.... http://www.mathworks.com/help/toolbox/mupad/datatypes/DOM_IDENT.html#DOM_IDENT
Additionally, an arbitrary string of characters enclosed in ‘backticks’ `` is also an identifier. Examples: `x+y`, `a plus 1`. If the string of characters between the back ticks is a valid identifier already, this input form creates the same identifier as the one without the backticks.
Thus, you could substitute (say) `I ` (with a space) where you have the variable I in your input, and the only visible difference with normal typesetting turned on would be an extra space after the I .

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!