Evaluating trigonometric expressions in sympy
<p>Using python 2.7 with PyCharm Community Edition 2016.2.3 + Anaconda distribution.</p>

<p>I have an input similar to :</p>

<pre><code>from sympy import *

x = symbols('x')
f = cos(x)
print (f.subs(x, 25))
</code></pre>

<p>The output is <code>cos(25)</code>, . Is there a way to evaluate trigonometric identities such as sin/cos, at a certain angle ? I've tried <code>cos(degrees(x))</code>, but nothing differs. Am I missing some crucial part of documentation or there really isn't a way to do this ? Ty for your help :)</p>

<p>Perform a <em>numerical evaluation</em> using <a href="http://docs.sympy.org/latest/modules/evalf.html#numerical-evaluation" rel="nofollow">function <code>N</code></a>:</p>

<pre><code>&gt;&gt;&gt; from sympy import N, symbols, cos
&gt;&gt;&gt; x = symbols('x')
&gt;&gt;&gt; f = cos(x)
&gt;&gt;&gt; f.subs(x, 25)
cos(25)
&gt;&gt;&gt; N(f.subs(x, 25)) # evaluate after substitution 
0.991202811863474
</code></pre>

<p>To make the computation in degrees, convert the angle to radians, using <a href="http://docs.sympy.org/0.6.7/modules/mpmath/functions/trigonometric.html#radians" rel="nofollow"><code>mpmath.radians</code></a>, so the computation is performed on a <em>rad</em> value:</p>

<pre><code>&gt;&gt;&gt; from symspy import mpmath
&gt;&gt;&gt; f.subs(x, mpmath.radians(25))
0.906307787036650
</code></pre>

<hr>

<p>Importing with <code>*</code> (wildcard imports) isn't a very good idea. Imagine what happens if you equally did <code>from math import *</code>, then one of the <code>cos</code> functions from both modules will be out in the wild.</p>

<p>See the <a href="https://www.python.org/dev/peps/pep-0008/#imports" rel="nofollow">PEP 8 guideline on imports</a>.</p>

python numpy trigonometry sympy