如何让 Sympy(在 python 中)插入函数的给定值?
How do get Sympy (in python) to plug in a given value for a function?
所以我目前正在学习微积分 2,我们最近开始讨论泰勒级数(是的......),因为它是一个非常难的话题,我的老师建议我们编写一个能够执行泰勒级数的编程代码为了更好地理解力学。到目前为止,这真的很有帮助,我能够让它找到 4 个导数,但我不确定如何让它将正确的 C 值插入函数和 4 个导数。有人可以告诉我下一步做什么吗?感谢:
import sympy as sy
sy.init_printing()
H=0
#Variables
while H!=100:
x=sy.symbols("x")
f=(input('Please enter function, x '))
c=int(input('Enter the center of the equasion, c '))
#Derivatives
dx=sy.Derivative(f)
dx=dx.doit()
Dx=sy.Derivative(dx)
Dx=Dx.doit()
DX=sy.Derivative(Dx)
DX=DX.doit()
D_X=sy.Derivative(DX)
D_X=D_X.doit()
H=H+1
print('The First Deritive, is:')
print(dx)
print('The Second Deritive, is:')
print(Dx)
print('The Third Deritive, is:')
print(DX)
print('The Fourth Deritive, is:')
print(D_X)
请允许我指出,d1x
、d2x
、d3x
和 d4x
的名称要比 dx
、[=16= 好得多]、DX
和D_X
。
print('The First derivative, is:')
print(dx)
print(f'The value of the first derivative at {c} is:')
print(dx.subs(x,c))
print('The Second derivative, is:')
print(Dx)
print(f'The value of the second derivative at {c} is:')
print(Dx.subs(x,c))
print('The Third derivative, is:')
print(DX)
print(f'The value of the third derivative at {c} is:')
print(DX.subs(x,c))
print('The Fourth derivative is:')
print(D_X)
print(f'The value of the fourth derivative at {c} is:')
print(D_X.subs(x,c))
所以我目前正在学习微积分 2,我们最近开始讨论泰勒级数(是的......),因为它是一个非常难的话题,我的老师建议我们编写一个能够执行泰勒级数的编程代码为了更好地理解力学。到目前为止,这真的很有帮助,我能够让它找到 4 个导数,但我不确定如何让它将正确的 C 值插入函数和 4 个导数。有人可以告诉我下一步做什么吗?感谢:
import sympy as sy
sy.init_printing()
H=0
#Variables
while H!=100:
x=sy.symbols("x")
f=(input('Please enter function, x '))
c=int(input('Enter the center of the equasion, c '))
#Derivatives
dx=sy.Derivative(f)
dx=dx.doit()
Dx=sy.Derivative(dx)
Dx=Dx.doit()
DX=sy.Derivative(Dx)
DX=DX.doit()
D_X=sy.Derivative(DX)
D_X=D_X.doit()
H=H+1
print('The First Deritive, is:')
print(dx)
print('The Second Deritive, is:')
print(Dx)
print('The Third Deritive, is:')
print(DX)
print('The Fourth Deritive, is:')
print(D_X)
请允许我指出,d1x
、d2x
、d3x
和 d4x
的名称要比 dx
、[=16= 好得多]、DX
和D_X
。
print('The First derivative, is:')
print(dx)
print(f'The value of the first derivative at {c} is:')
print(dx.subs(x,c))
print('The Second derivative, is:')
print(Dx)
print(f'The value of the second derivative at {c} is:')
print(Dx.subs(x,c))
print('The Third derivative, is:')
print(DX)
print(f'The value of the third derivative at {c} is:')
print(DX.subs(x,c))
print('The Fourth derivative is:')
print(D_X)
print(f'The value of the fourth derivative at {c} is:')
print(D_X.subs(x,c))