Ask Your Question

understanding complex numbers from solve()

asked 2016-08-02 14:33:00 -0600

etb gravatar image

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)

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), the atrocity

fs1 = fs[0]  # they seem identical so I take the first item 
fs2 = numerical_approx(fs1.rhs())
fs3 = fs2[0] # simply shaving off the complex number
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-08-02 15:12:34 -0600

calc314 gravatar image

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.

solns=[s.rhs() for s in ans]
real_solns=[s.n() for s in solns if imag_part(s)==0]
edit flag offensive delete link 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?

etb gravatar imageetb ( 2017-02-09 02:04:13 -0600 )edit

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.

calc314 gravatar imagecalc314 ( 2017-02-13 07:40:53 -0600 )edit

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?

etb gravatar imageetb ( 2017-02-14 07:46:58 -0600 )edit

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

calc314 gravatar imagecalc314 ( 2017-03-01 08:12:04 -0600 )edit

@calc314, this is super helpful. Thanks!

etb gravatar imageetb ( 2017-03-18 09:20:30 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-08-02 14:33:00 -0600

Seen: 765 times

Last updated: Aug 02 '16