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
採用された回答
その他の回答 (1 件)
Sean de Wolski
2011 年 8 月 18 日
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 件のコメント
Junior
2011 年 8 月 18 日
Sean de Wolski
2011 年 8 月 18 日
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.
Paulo Silva
2011 年 8 月 18 日
I don't see that "bug" on my MATLAB 2008b sym('I') gives I, try this:
reset(symengine)
Sean de Wolski
2011 年 8 月 18 日
Paulo: sym('A+I')
Walter Roberson
2011 年 8 月 18 日
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 .
カテゴリ
ヘルプ センター および File Exchange で Operations on Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!