Python `sympy` module equation solving multiplication in expression -


i have code below simple test of sympy.solve:

#!/usr/bin/python  sympy import *  x = symbol('x', real=true) #expr = sympify('exp(1 - 10*x) - 15')  expr = exp(1 - x) - 15 print "expressiong:", expr out = solve(expr) item in out:     print "answer:", item  expr = exp(1 - 10*x) - 15 print expr out = solve(expr) item in out:     print "answer:", item 

output follows:

expressiong: exp(-x + 1) - 15 answer: -log(15) + 1 exp(-10*x + 1) - 15 answer: log(15**(9/10)*exp(1/10)/15) 

the equation exp(1 - x) = 15 solved correctly (x = -15log(15) + 1).

but when change x 10*x, result weird.

  1. why there lot of complex answers if initialize symbol x without real=true?

  2. even real=true when initializing symbol x, answer still not correct. comparing first equation, result should -3/2*log(15) + 1/10. did write equation wrong?

thanks in advance.

i can confirm solve output equation exp(1 - 10*x) - 15 == 0 appears unecessarily complicated. suggest univariate equations first consider sympy.solveset. example, gives following nicely formatted solutions.

import sympy sp sp.init_printing(pretty_print=true)  x = sp.symbols('x')  sp.solveset(sp.exp(1 - 10*x) - 15,x) 

enter image description here

note there complex roots due exponential function being multi-valued (in complex domain). if want restrict domain of solution reals, solveset has convenient option domain purpose.

sp.solveset(sp.exp(1 - 10*x) - 15,x, domain = sp.s.reals) 

enter image description here


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -