# understanding complex numbers from solve()

I'm reproducing whats in my math book, or I am trying to. There's a relatively simply equation that I'm supposed to solve, at 8.5 and get 12,14013462. However, when I do this in Sage I get a whole string of complex numbers. I've figured out how to reduce this glory of symbols of numbers into whats in my book, but I feel I am committing some form of atrocity, but maybe my book is simply off? Please let me know if this is not the place for questions like this.

I have this function and _solution_

f(x) = 10.28/(1+3.177*e^(-0.224*x))
fs = solve(f(x)==8.5, x)
show(fs)


However, here is what I get and it's not 12,14 (below is the code I use to cut down the glorious complexity to something that resembles what is in my book), fs1 = fs  # they seem identical so I take the first item
fs2 = numerical_approx(fs1.rhs())
fs3 = fs2 # simply shaving off the complex number
show(fs3)
type(fs3)

edit retag close merge delete

Sort by » oldest newest most voted

Unfortunately in general, you cannot just take the real part of the complex solutions and use that as a solution. Here is some code that finds the solutions and then returns the real number solution.

f(x)=10.28/(1+3.177*e^(-0.224*x))
ans=solve(f(x)==8.5,x)
solns=[s.rhs() for s in ans]
real_solns=[s.n() for s in solns if imag_part(s)==0]
real_solns

more

@calc314 thank you for your solution. Is this a math issue or a SageMath, i.e. is this problem due to something mathematical I am not aware of?

Yes, this is a math issue. For example, the solutions of $x^2+1=0$ are $x=\pm i$. You cannot use the real parts of these two solutions, which would be $0$, as a solution to the equation.

This is super helpful! Thanks. Is there a way to limit results to the real space? I looked at wolfram Alpha I can make such assumption explicit using [Simplifyx^2+1=0 Which is different from x^2+1=0, the latter allows fro complex solutions whereas the former doesn't. I trying looking around, but couldn't find a similar option in SM. Do you know where I can learn more about this?

1

Try starting with: assume(x,'real'). This now seems to limit your results from the solve command to the reals.