(Some function) is not defined with SymPy Lambdify

Viewed 5152

So I'm writing a script that evaluates Taylor Series. However, I want it to evaluate for all types of functions. So I tried, for example, using the function acot(x).

x = sy.Symbol('x')
f = acot(x)
...
func = taylor(f,0,3)
taylor_lambda = sy.lambdify(x, func, 'numpy')

The above runs without an exception (except if I use acsch, for example, and it does not run).

But then when it reaches this line:

plt.plot(x1,taylor_lambda(x1),label='taylor approximation')

I get:

NameError: name 'acot' is not defined

I tried to replace numpy with sympy in the lambdify call but this seems to evaluate symbolically. This is happening with some (more rare functions) but not for others. Thank you!

My imports are as follows:

import sympy as sy
import numpy as np
from sympy.functions import *
from sympy import pi, E,acot
import matplotlib.pyplot as plt
import math
2 Answers
Related