如何数值计算R中的渐近线?
how to numerically calculate the asymptote in R?
这个问题来源于那个
。
Maurits Evers 提供了可行的解决方案,
但我需要计算渐近线的结果在图中标记为红点。
所以这里是 lim
(\lim_{x \to \infty}\left(\frac{x}{x - 1} - 2\right)
)
这个函数的结果=-1
这个函数的结果(x / (x - 1) - 2) 在R中是如何计算的? , 然后在这个图上显示它
my_func <- function(x) x / (x - 1) - 2
library(ggplot2)
ggplot(data.frame(x = 0), aes(x)) +
stat_function(fun = my_func, aes(colour = "Function")) +
geom_hline(aes(yintercept = -1, colour = "Asymptote")) +
scale_colour_manual(values = c("Asymptote" = "blue", "Function" = "orange")) +
xlim(-10, 10) +
theme_minimal()
作为红点。
由于 R 符合国际标准,returns Inf/(Inf-1) 为 NaN,因此您需要为函数提供一个非常大的数字:
lim <- my_func(exp(100))
> lim
[1] -1
这个数字甚至可以更高。溢出发生在 exp(600) 和 exp(800) 之间的某个地方:
> exp(600)
[1] 3.77302e+260
> exp(800)
[1] Inf
这个问题来源于那个
所以这里是 lim
(\lim_{x \to \infty}\left(\frac{x}{x - 1} - 2\right)
)
这个函数的结果=-1
这个函数的结果(x / (x - 1) - 2) 在R中是如何计算的? , 然后在这个图上显示它
my_func <- function(x) x / (x - 1) - 2
library(ggplot2)
ggplot(data.frame(x = 0), aes(x)) +
stat_function(fun = my_func, aes(colour = "Function")) +
geom_hline(aes(yintercept = -1, colour = "Asymptote")) +
scale_colour_manual(values = c("Asymptote" = "blue", "Function" = "orange")) +
xlim(-10, 10) +
theme_minimal()
作为红点。
由于 R 符合国际标准,returns Inf/(Inf-1) 为 NaN,因此您需要为函数提供一个非常大的数字:
lim <- my_func(exp(100))
> lim
[1] -1
这个数字甚至可以更高。溢出发生在 exp(600) 和 exp(800) 之间的某个地方:
> exp(600)
[1] 3.77302e+260
> exp(800)
[1] Inf