Why do I get an erroneous complex resultwhen using SOLVE on an equation containing a symbolic variable called "I"?

1 view (last 30 days)
I use the SOLVE function and I get a result that has imaginary components. My equation includes a symbolic variable, I, which has been interpreted as the imaginary number i (the square root of -1). This happens despite the SYMVAR function listing I as a symbolic variable.
For instance, create the following equation and list the symbols involved:
eqn = 'x = I^2';
symvar(eqn)
ans =
'I'
'x'
However, when SOLVE is used, "I" is not treated as a symbol, but instead is treated as "sqrt(-1)":
solve(eqn,'x')
ans =
-1

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
The SYMVAR command is a MATLAB function which does not interface with MuPAD or the symbolic toolbox when interpreting a string. Using the following syntax would give the correct symbolic variables:
symvar(sym(eqn))
Currently, when using strings with SOLVE and DSOLVE, the names inside are the MuPAD names. So "I" is the MuPAD "I" which is sqrt(-1).
The workarounds would be:
1) use another name besides I or
2) use sym objects:
syms x I
solve(x^2-I,x)

More Answers (0)

Products


Release

R2009a

Community Treasure Hunt

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

Start Hunting!