【问题标题】:Graphing any rational functions in python considering the asymptotes [closed]考虑渐近线在python中绘制任何有理函数[关闭]
【发布时间】:2016-08-20 15:08:22
【问题描述】:

如何在 python matplotlib 中绘制任何有理函数(考虑渐近线)

numerator = input ("numerator: ")
denominator = input ("denominator: ")

【问题讨论】:

  • 请在提问时提供更多信息并提出一些具体问题。如果有人特别指出我可以帮助您的事情,我会更容易提供答案。

标签: python python-3.x numpy matplotlib tkinter


【解决方案1】:

我假设您目前在尝试使用 matplotlib 绘制的某些函数的渐近/不连续行为方面遇到问题。不久前在 StackOverflow 上发布了关于此主题的类似问题:how to handle an asymptote/discontinuity with Matplotlib

我将冒昧复制@paul 提供的有用代码 sn-p 作为对这个问题的答案:

# setup x and y ranges and precision
xx = np.arange(-0.5,5.5,0.01)

max_tolerance = 100.
min_tolerance = -100.

yy = 1/(xx-2)
yy[yy > max_tolerance] = np.inf
yy[yy < min_tolerance] = -np.inf

ax.plot(xx, yy, zorder=100, linewidth=3, color='red') 

如果其中一些代码没有意义,请点击我在上面发布的问题的链接。那里显示了绘制具有渐近/不连续行为的数据所需的所有源代码。

希望对你有帮助!

【讨论】:

  • 谢谢,但是如果你有一个斜渐近线,那么你需要一个算法来处理长除法,以便找到渐近线的方程。
  • 我明白了!现在你为什么显示numeratordenominator 变量更有意义了。好吧,首先您必须编写逻辑以确保分子的度数高于分母。现在假设:x = np.arange(-30, 30, 0.05)numerator = (x^2 - 6*x + 7)denominator = (x + 5)。让我们调用渐近线函数yy = numerator / denominator。您需要做的就是运行相同的绘图命令(首先确保您使用的 x 轴变量和 y 轴变量名称匹配)。
猜你喜欢
  • 2021-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-03
相关资源
最近更新 更多