我正在研究一个Python脚本,该脚本将数学函数作为输入并吐出有用的信息以绘制该函数的曲线(切线,交点,渐近线等),第一步是找到定义域该函数的有效性(当该函数有效时,例如:1 / x-2 df =]-∞,2 [U] 2,+∞[),我需要使用sympy来完成。 下面是在制品代码
from sympy import *
from fractions import *
x = symbols('x')
f = Function('f')
f = input('type function: ')
fp = diff(f)
sol = solve(f, x)
sol_p = solve(fp, x)
print(f"f(x)={f},f'(x)={fp}")
#print(f"x1={sol[0]},x2={sol[1]},x'={sol_p}")
print(f'{len(sol)}')
psol = {}
limits_at_edges = {}
df = solveset(f, x, domain=S.Reals)
for i in range(1,( len(sol) + 1)): # Prints out every item in sol[] after aplying .evalf()
psol["x" + str(i) ] = sol[i - 1].evalf()
for i in range(1, len(sol) + 1):
limits_at_edges[f'limit x -> x{i} f(x)'] = limit(f, x, sol[i - 1])
print(f'Solution:{sol}')
print(f'Processes solution:{psol}')
print(f'Derivative solution:{sol_p}')
print(limits_at_edges)
print(f'Domain:{df}')
pprint(f, use_unicode=True)
答案 0 :(得分:0)
这个问题类似于How to know whether a function is continuous with sympy?
可以按照here的说明使用continuous_domain
完成此操作。