2017-10-30 6 views
-1
import sympy as sp 
def taylorCoefficient(f, a, n): 
    x = sp.symbols("x") 
    coefficient = [] 
    for i in range(0, n + 1): 
     afgeleide = sp.diff(f(x), x, n=n) 
     def f(x0): return afgeleide.subs(x, x0) 
     coefficient += f(a)/sp.factorial(n) 
    return coefficient 


x = sp.symbols("x") 
taylorCoefficient(x ** 2 * sp.sin(x/2), 0, 3) 

나는 mul 객체를 호출 할 수 없지만 왜 호출 할 수 있습니까? (온라인 afgeleide = ...)"mul 객체를 호출 할 수 없습니다."-error

+1

역 추적 –

+1

'f '는 호출 할 수없는'Mul' 객체이기 때문에. 기대 했니? 왜? – Goyo

답변

0

스크립트의 마지막 줄을 taylorCoefficient(lambda x: x**2*sp.sin(x/2), 0, 3)으로 변경해보십시오.