如何知道一个函数是否与sympy连续? [英] How to know whether a function is continuous with sympy?
问题描述
我需要定义一个函数来检查输入函数在具有 sympy 的点上是否连续.
我用关键字连续性"搜索了 sympy 文档,但没有现有的功能.我想也许我应该考虑有限制地去做,但我不确定如何.
def check_continuity(f, var, a):尝试:f = sympify(f)除了 SymifyError:return("无效输入")别的:x1 = 符号(var,正 = 真)x2 = 符号(var,负 = 真)//我不知道这之后该怎么办
是的,您需要使用限制.
某一点连续性的正式定义必须满足三个条件.函数 f(x) 在 x = c if
处连续- lim x —> c f(x) 存在
- f(c) 存在(也就是说,c 在 f 的域中.)
- lim x —> c f(x) = f(c>)
SymPy 可以使用 limit 函数计算符号限制.
<预><代码>>>>限制(罪(x)/x,x,0)1参见:https://docs.sympy.org/latest/tutorial/calculus.html#limits
I need to define a function that checks if the input function is continuous at a point with sympy.
I searched the sympy documents with the keyword "continuity" and there is no existing function for that. I think maybe I should consider doing it with limits, but I'm not sure how.
def check_continuity(f, var, a):
try:
f = sympify(f)
except SympifyError:
return("Invaild input")
else:
x1 = Symbol(var, positive = True)
x2 = Symbol(var, negative = True)
//I don't know what to do after this
Yes, you need to use the limits.
The formal definition of continuity at a point has three conditions that must be met. A function f(x) is continuous at a point where x = c if
- lim x —> c f(x) exists
- f(c) exists (That is, c is in the domain of f.)
- lim x —> c f(x) = f(c)
SymPy can compute symbolic limits with the limit function.
>>> limit(sin(x)/x, x, 0)
1
See: https://docs.sympy.org/latest/tutorial/calculus.html#limits
这篇关于如何知道一个函数是否与sympy连续?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!