如何解决如何让 Sympy在 python 中插入函数的给定值?
所以我目前在学习微积分 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
、Dx
更好, 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))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。