Ask Your Question
0

understanding complex numbers from solve()

asked 2016-08-02 21:33:00 +0200

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)
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), 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
show(fs3)
type(fs3)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-08-02 22:12:34 +0200

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.

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
edit flag offensive delete link more

Comments

@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 09:04:13 +0200 )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 14:40:53 +0200 )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 14:46:58 +0200 )edit
1

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 15:12:04 +0200 )edit

@calc314, this is super helpful. Thanks!

etb gravatar imageetb ( 2017-03-18 15:20:30 +0200 )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

Stats

Asked: 2016-08-02 21:33:00 +0200

Seen: 1,461 times

Last updated: Aug 02 '16