# Getting complex solutions from solve in SymPy.jl

**URL:** <https://discourse.julialang.org/t/getting-complex-solutions-from-solve-in-sympy-jl/3292>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 20, 2017, 12:25am UTC](https://discourse.julialang.org/t/getting-complex-solutions-from-solve-in-sympy-jl/3292 "2017-04-20T00:25:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [April 20, 2017, 12:25am UTC](https://discourse.julialang.org/t/getting-complex-solutions-from-solve-in-sympy-jl/3292/1 "2017-04-20T00:25:15Z")

</div>

### Paraphrased from [SymPy Issue #150](https://github.com/JuliaPy/SymPy.jl/issues/150).

* * *

#### Description:

I’m trying to get a real solution from 4 complex solutions that encircle it.

What I’m trying to do is take the `norm` of the 4 solutions and scale it.

However the scaling turns the value back into a complex number.

Is there a way to have my cake and eat it too? // get the real solution

* * *

**edit:** i’m now investigating non-norm scaling options

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [April 20, 2017, 5:22pm UTC](https://discourse.julialang.org/t/getting-complex-solutions-from-solve-in-sympy-jl/3292/2 "2017-04-20T17:22:00Z")

</div>

Summarized:

```julia
cur_ignition_requirement = ignition_requirement()

cur_R_0 = symbol_dict["R_0"]

solved_system = SymPy.solve(cur_ignition_requirement, cur_R_0)

```

returns

```julia
-I*(-1.15+29*B_0^0.15*T_k^0.96*sigma_v_hat*(1/(-17.0*sigma_v_hat + 19))^0.93/(-8.88+37*T_k*sigma_v_hat^0.69*(-1/(88.0*sigma_v_hat - 98))^0.97 + 7.9+37*T_k*sigma_v_hat^1.69*(-1/(88.0*sigma_v_hat - 98))^0.97) + 3.43297327500117e+26*B_0^0.15*T_k^1.46*(1/(-17.0*sigma_v_hat + 19))^0.93/(-8.88+37*T_k*sigma_v_hat^0.69*(-1/(88.0*sigma_v_hat - 98))^0.97 + 7.9+37*T_k*sigma_v_hat^1.69*(-1/(88.0*sigma_v_hat - 98))^0.97))^(25/4)
I*(-1.15+29*B_0^0.15*T_k^0.96*sigma_v_hat*(1/(-17.0*sigma_v_hat + 19))^0.93/(-8.88+37*T_k*sigma_v_hat^0.69*(-1/(88.0*sigma_v_hat - 98))^0.97 + 7.9+37*T_k*sigma_v_hat^1.69*(-1/(88.0*sigma_v_hat - 98))^0.97) + 3.43297327500117e+26*B_0^0.15*T_k^1.46*(1/(-17.0*sigma_v_hat + 19))^0.93/(-8.88+37*T_k*sigma_v_hat^0.69*(-1/(88.0*sigma_v_hat - 98))^0.97 + 7.9+37*T_k*sigma_v_hat^1.69*(-1/(88.0*sigma_v_hat - 98))^0.97))^(25/4)
-(-1.15+29*B_0^0.15*T_k^0.96*sigma_v_hat*(1/(-17.0*sigma_v_hat + 19))^0.93/(-8.88+37*T_k*sigma_v_hat^0.69*(-1/(88.0*sigma_v_hat - 98))^0.97 + 7.9+37*T_k*sigma_v_hat^1.69*(-1/(88.0*sigma_v_hat - 98))^0.97) + 3.43297327500117e+26*B_0^0.15*T_k^1.46*(1/(-17.0*sigma_v_hat + 19))^0.93/(-8.88+37*T_k*sigma_v_hat^0.69*(-1/(88.0*sigma_v_hat - 98))^0.97 + 7.9+37*T_k*sigma_v_hat^1.69*(-1/(88.0*sigma_v_hat - 98))^0.97))^(25/4)
(-1.15+29*B_0^0.15*T_k^0.96*sigma_v_hat*(1/(-17.0*sigma_v_hat + 19))^0.93/(-8.88+37*T_k*sigma_v_hat^0.69*(-1/(88.0*sigma_v_hat - 98))^0.97 + 7.9+37*T_k*sigma_v_hat^1.69*(-1/(88.0*sigma_v_hat - 98))^0.97) + 3.43297327500117e+26*B_0^0.15*T_k^1.46*(1/(-17.0*sigma_v_hat + 19))^0.93/(-8.88+37*T_k*sigma_v_hat^0.69*(-1/(88.0*sigma_v_hat - 98))^0.97 + 7.9+37*T_k*sigma_v_hat^1.69*(-1/(88.0*sigma_v_hat - 98))^0.97))^(25/4)

```

// i.e. `-I*blah`, `+I*blah`, `-1*blah`, `+1*blah`

* * *

I want to get a real solution from this, by doing:

1st:

```julia
an_eq = norm(solved_system)

```

2nd:

```julia
a_constant = -0.8918
an_eq *= a_constant

```

The constant, `a_constant`, was chosen to make `an_eq` the correct value after substitutions are made.

However, when actually doing the scaling, a complex number comes out of the substituted mess.

* * *

I’d appreciate any help. Please ask me to clarify anything that doesn’t make sense.

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [April 21, 2017, 4:22pm UTC](https://discourse.julialang.org/t/getting-complex-solutions-from-solve-in-sympy-jl/3292/3 "2017-04-21T16:22:36Z")

</div>

i’ve been thinking about it and maybe the problem stems from not simplifying:

`-2282.55434896033*(1/(-175329.0*sigma_v + 196349.540849362))^(93/100)/(sigma_v^(69/100)*(-1/(87664500000000.0*sigma_v - 98174770424681.0))^(97/100)*(87664500000000.0*sigma_v - 98174770424681.0))`

Do you know how this could be done? I’ve been trying the slew of SymPy methods, but can’t get any of them to work.

One thing I’d really like is to do is a `collect` on:

`collect_symbol = ( 1 - K_CD() * sigma_v )`
