r - 像 Wolframalpha 网站上那样绘制多项式函数,以便于理解

标签 r function plot wolframalpha

在 Wolfram-alpha-网站 中绘制函数如下所示:

enter image description here

http://www.wolframalpha.com/link

在 R 中绘制相同的函数如下所示:

绘图(函数(x)x^2 - 3*x - 10 ) enter image description here

Wolfram 的默认绘图更容易理解。我认为这是因为它显示了 x 轴(在 y=0 处),并将抛物线居中。

我的数学能力不够好,无法只看函数的公式并看看应该在哪里居中绘图,并且我正在绘制函数以了解不同的函数如何创建不同的线,所以我需要这个居中自动完成,否则我可能会误解情节。

是否可以自动创建 Wolfram 图,即无需我告诉 R 将图置于中心位置是明智的?

最佳答案

polynom 包将创建一些合理的默认值。

例如。

library(polynom)

# your polynomial (coefficients in ascending powers of x order)
p <- polynomial(c(-10,-3,1))
plot(p)

enter image description here

 # a more complicated example, a polynomial crossing the x axis at -1,0,1,2,3,4,5

 p2 <- poly.calc(-1:5)
 p2 
 # -120*x + 154*x^2 + 49*x^3 - 140*x^4 + 70*x^5 - 14*x^6 + x^7 
 plot(p2)

enter image description here

关于r - 像 Wolframalpha 网站上那样绘制多项式函数,以便于理解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20251653/

相关文章:

python - 从 Python 到 R 的 if-else 函数

r - directlabels geom_dl() 中的标签大小

r - 在 R Shiny 应用程序中使用滚动条绘制大图

android - 如何停止AChartEngine动态折线图沿y轴滚动?

r - 如何随机命名数据框的列或行?

r - 如何在特定文本匹配上替换 R 中的值 NA

html - Angular 4 在 *ngFor 内调用函数时卡住

R - 比较两个数据集时如何避免循环?

r - 按元素名称合并/合并列表(列表中的列表)

javascript - 使用外部加载的链接执行 JavaScript 函数