关于Freudenstein方程的讨论中的错误

时间:2013-05-28 14:33:17

标签: python sympy

我正试图获得Freudenstein方程(psi)的一个角度:

k1 * cos(psi) - k2 * cos(fi)+ k3 - cos(psi - fi)= 0

我有k1,k2,k3和fi值。我尝试了以下方法:

from sympy import Symbol, solve, cos

x = Symbol('x')
realPsi = solve(k1 * cos(x) - k2 * cos(fi) + k3 - cos(x - fi), x)

我收到此错误:

File "/usr/lib/python2.7/dist-packages/sympy/solvers/solvers.py", line 484, in solve solution = _solve(f, *symbols, **flags)  
File "/usr/lib/python2.7/dist-packages/sympy/solvers/solvers.py", line 700, in _solve soln = tsolve(f_num, symbol)
File "/usr/lib/python2.7/dist-packages/sympy/solvers/solvers.py", line 1143, in tsolve "(tsolve: at least one Function expected at this point")
NotImplementedError: Unable to solve the equation(tsolve: at least one Function expected at this point

我以前不使用这种工具,也许我做错了什么...... 有什么想法吗?

谢谢,

埃克托。

编辑:
谢谢你的快速反应。

我尝试了以下(带cos的简单方程式):

eq = 3.2 * cos(x + 0.2).rewrite(exp) + 1.7   

eq   

Out[1]: 1.6*exp(I*(-x - 0.2)) + 1.6*exp(I*(x + 0.2)) + 1.7   

solve(1.6*exp(I*(-x - 0.2)) + 1.6*exp(I*(x + 0.2)) + 1.7, x)

NotImplementedError: Unable to solve the equation(tsolve: at least one Function expected at this point  

我正确使用.rewrite ??

2 个答案:

答案 0 :(得分:2)

NotImplementedError表示它所说的,即这种方程式的求解器“未实现”。

您可以帮助SymPy找到解决方案:

>>> k * cos(x) - m * cos(y) + n - cos(x - y)
k*cos(x) - m*cos(y) + n - cos(x - y)
>>> _.rewrite(exp)
k*(exp(I*x)/2 + exp(-I*x)/2) - .....
>>> solve(_, x)
..... long solution

您可以使用rewrite将使用三角函数编写的表达式转换为包含复指数的表达式。

答案 1 :(得分:2)

当然应该"只是工作"但是这里有一个案例,在这个简单的方程式中使用cos"如上所述,您可以得到答案:

>>> eq=3.2*cos(x+.2)+1.7
>>> [w.n(3,chop=True) for w in solve(expand(eq.rewrite(exp)))]
[-2.33, 1.93]