Python solve equation for one variable

后端 未结 5 2011
逝去的感伤
逝去的感伤 2021-02-06 11:08

I\'m trying to solve an equation in python using SymPy. I have a generated equation (something like function = y(8.0-(y**3.0)) which I use with SymPy to create a ne

5条回答
  •  我寻月下人不归
    2021-02-06 11:43

    For nonlinear equations, you should use sympy.solvers.nsolve to solve it numerically, except for some special cases where a more specific and appropriate solver may exist (e.g. tsolve).

    For example, the following script should output 1.2667664310254.

    from sympy import Symbol
    from sympy.solvers import nsolve
    from sympy import sin, tan
    
    theta = Symbol('theta')
    print nsolve(tan(theta)/(1+1*sin(theta)) - 4.0**2/9.81, theta, (1.2,))
    

提交回复
热议问题