Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
742 views
in Technique[技术] by (71.8m points)

sympy - Solve non linear equation with one variable Python

I am trying to solve the following equation in python with sympy.

13000*1.44**x =1000000

I tried:

x = symbols('x', real=True) 
print(solveset(Eq(130000*1.44**x, 1000000), x))

Now this does gives:

ConditionSet(x, Eq(1.44**x - 100/13, 0), Complexes)

Is this equation not suitable for solveset? Do I need to solve this with fsolve?

Thanks in advance


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The reason you are getting this answer is because there are infinitely many solutions over the complex numbers. Assuming you just want real numbers, try using solveset_real:

from sympy.solvers.solveset import solveset_real

x = symbols('x', real=True)
print(solveset_real(Eq(130000*1.44**x, 1000000), x))

gets you

FiniteSet(2.74240747387354*log(100/13))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...