Re: [sympy] Solve does not handle trigonometric equations

56 views
Skip to first unread message

Chris Smith

unread,
May 22, 2013, 12:20:02 AM5/22/13
to sympy
In the current master [1] you get

```
>>> solve(sin(x)+tan(x))
[0, 2*pi]
>>> solve(sin(x)+sec(x))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy\solvers\solvers.py", line 834, in solve
    solution = _solve(f[0], *symbols, **flags)
  File "sympy\solvers\solvers.py", line 1339, in _solve
    result = _tsolve(f_num, symbol, **flags)
  File "sympy\solvers\solvers.py", line 2166, in _tsolve
    return _solve(rewrite - rhs, sym)
  File "sympy\solvers\solvers.py", line 1345, in _solve
    "\nNo algorithms are implemented to solve equation %s" % f)
NotImplementedError: multiple generators [exp(I*x), sec(x)]
No algorithms are implemented to solve equation sec(x)
```

But give that a little help by rewriting it and it works:

```
>>> solve((sin(x)+sec(x)).rewrite(cos)
... )
[-2*atan(-1/2 + sqrt(2 - 2*sqrt(3)*I)/2 + sqrt(3)*I/2), 2*atan(1/2 - sqrt(3)*I/2
 + sqrt(2 - 2*sqrt(3)*I)/2), 2*atan(1/2 - sqrt(2 + 2*sqrt(3)*I)/2 + sqrt(3)*I/2)
, 2*atan(1/2 + sqrt(2 + 2*sqrt(3)*I)/2 + sqrt(3)*I/2)]
```

Chris Smith

unread,
May 22, 2013, 12:21:16 AM5/22/13
to sympy
[1] http://tinyurl.com/7oqpu7v  (how to get the most recent SymPy)

Abhishek kumawat

unread,
May 22, 2013, 12:34:33 AM5/22/13
to sy...@googlegroups.com
I installed the latest using git and tried your example using rewrite:

<ipython-input-7-6d87796777b3> in <module>()
----> 1 solve(sin(x)+sec(x)).rewrite(cos)

C:\Python27\lib\site-packages\sympy\core\expr.pyc in __float__(self)
    239         if result.is_number and result.as_real_imag()[1]:
    240             raise TypeError("can't convert complex to float")
--> 241         raise TypeError("can't convert expression to float")
    242
    243     def __complex__(self):

TypeError: can't convert expression to float

Chris Smith

unread,
May 22, 2013, 1:33:22 AM5/22/13
to sympy
Did you check to see that you didn't set x to something? This will be fixed, btw, with PR 1964 so you don't have to do the rewrite manually.

Chris Smith

unread,
May 22, 2013, 1:59:50 AM5/22/13
to sympy
You are missing a left paren after "solve" and then a closing one:

solve(sin(x)+sec(x)).rewrite(cos) -->
solve((sin(x)+sec(x)).rewrite(cos))

Chris Smith

unread,
May 22, 2013, 2:00:34 AM5/22/13
to sympy
Note that this will "just work" in PR 1964.
Reply all
Reply to author
Forward
0 new messages