COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### solve - Undefined function or variable 'I'

• Email
• Follow

```Dear all,

I am trying to solve a simple one variable equation from a 3rd order polynomial function but I get a variable called "I" in the solution that avoids me to evaluate them to choose the right one.
I am sure there is a real solution (and more or les I know the range where it has to be) as you can see in the figure...
Any ideas how to get rid of this I, or why is it appearing? any alternatives?

Thanks a lot!

Jordi

syms x n;
Qn=2000; Hn=20;
H1 = -2.2786e-010*x^3+7.2496e-007*x^2-0.0032*x+55.1004;
H1_=subs(H1,{x},{Qn*n});
S1 = H1_ - 20*n^2;
n_= solve('H1_ - 20*n^2','n');

figure; plot([-2:0.1:2],subs(S1,{n},[-2:0.1:2]));
```
 0
Reply JORDI 11/29/2010 3:57:04 PM

See related articles to this posting

```On 29/11/10 9:57 AM, JORDI wrote:

> I am trying to solve a simple one variable equation from a 3rd order
> polynomial function but I get a variable called "I" in the solution that
> avoids me to evaluate them to choose the right one.
> I am sure there is a real solution (and more or les I know the range
> where it has to be) as you can see in the figure...
> Any ideas how to get rid of this I, or why is it appearing? any
> alternatives?

"I" is the symbolic representation of sqrt(-1), the imaginary unit.

> S1 = H1_ - 20*n^2;
> n_= solve('H1_ - 20*n^2','n');

n_ = solve(S1, n);

would be better. When you use a quoted string for solve, it passes the
string exactly as-is to the symbolic engine, and any value you have
given to variables at the Matlab level will not be used. The symbolic
computations you do at the Matlab level are not transferred to the
symbolic engine unless you specifically ask for them to be transferred.
This is not an issue when you pass a symbolic object such as S1 to
solve() but *is* an issue when you pass a quoted string to solve().
```
 0
Reply Walter 11/29/2010 4:13:01 PM

```Thanks Walter!

I understand your suggestion, I've already tried it and still get this 'I' in the solution, but I think I would at least get a real solution, you can actually see it in the figure created.
What do you think?

Jordi

Walter Roberson <roberson@hushmail.com> wrote in message <hiQIo.243\$hy4.17@newsfe17.iad>...
> On 29/11/10 9:57 AM, JORDI wrote:
>
> > I am trying to solve a simple one variable equation from a 3rd order
> > polynomial function but I get a variable called "I" in the solution that
> > avoids me to evaluate them to choose the right one.
> > I am sure there is a real solution (and more or les I know the range
> > where it has to be) as you can see in the figure...
> > Any ideas how to get rid of this I, or why is it appearing? any
> > alternatives?
>
> "I" is the symbolic representation of sqrt(-1), the imaginary unit.
>
>  > S1 = H1_ - 20*n^2;
>  > n_= solve('H1_ - 20*n^2','n');
>
> n_ = solve(S1, n);
>
> would be better. When you use a quoted string for solve, it passes the
> string exactly as-is to the symbolic engine, and any value you have
> given to variables at the Matlab level will not be used. The symbolic
> computations you do at the Matlab level are not transferred to the
> symbolic engine unless you specifically ask for them to be transferred.
> This is not an issue when you pass a symbolic object such as S1 to
> solve() but *is* an issue when you pass a quoted string to solve().
```
 0
Reply JORDI 11/29/2010 4:27:03 PM

```
"JORDI " <jordiforever@gmail.com> wrote in message
news:id0k8n\$o79\$1@fred.mathworks.com...
> Thanks Walter!
>
> I understand your suggestion, I've already tried it and still get this 'I'
> in the solution, but I think I would at least get a real solution, you can
> actually see it in the figure created.
> What do you think?

Just because an expression contains I does not mean it does not represent a
real value.  One example:

http://en.wikipedia.org/wiki/Trigonometry#Euler.27s_formula

If you want the numeric value of your expression without an I in it, you can
try to use VPA or DOUBLE.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

```
 0
Reply Steven_Lord 11/29/2010 4:50:47 PM

```On 29/11/10 10:27 AM, JORDI wrote:

> I understand your suggestion, I've already tried it and still get this
> 'I' in the solution, but I think I would at least get a real solution,
> you can actually see it in the figure created.
> What do you think?

I do not have the symbolic toolbox, so I cannot try your code myself.

You appear to have a cubic. It is not uncommon for a cubic to have two
imaginary solutions and one real solution. When you solve() you would
get all three solutions.

The code you showed does not make use of the results of the solve(). You
stored the results of the solve into n_ but you have

plot([-2:0.1:2],subs(S1,{n},[-2:0.1:2]));

S1 is just the symbolic form of the equation itself, not of the
solution, and n is your symbolic variable, not the solution to solve().

You need to expect multiple solutions from solve() and you need to pick
out which of the solutions you wish to graph.

If you wish to restrict the solution of solve() to real numbers, you
could add an "assumption" that n is real when you declare it as a
symbolic variable:

http://www.mathworks.com/help/toolbox/symbolic/syms.html

Syntax

syms arg1 arg2 ...
syms arg1 arg2 ... real
```
 0
Reply Walter 11/29/2010 4:57:11 PM

```Thanks a lot!

This is what I needed.
The solution is actually a real value, coefficients for imaginary term are all of them of the order of 10^(-40).

"Steven_Lord" <slord@mathworks.com> wrote in message <id0ll7\$rb0\$1@fred.mathworks.com>...
>
>
> "JORDI " <jordiforever@gmail.com> wrote in message
> news:id0k8n\$o79\$1@fred.mathworks.com...
> > Thanks Walter!
> >
> > I understand your suggestion, I've already tried it and still get this 'I'
> > in the solution, but I think I would at least get a real solution, you can
> > actually see it in the figure created.
> > What do you think?
>
> Just because an expression contains I does not mean it does not represent a
> real value.  One example:
>
> http://en.wikipedia.org/wiki/Trigonometry#Euler.27s_formula
>
> If you want the numeric value of your expression without an I in it, you can
> try to use VPA or DOUBLE.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com
```
 0
Reply JORDI 11/29/2010 5:04:03 PM

5 Replies
578 Views

Similar Articles

12/2/2013 12:34:38 PM
page loaded in 29029 ms. (0)