R:绘制函数,"不是图形参数"

时间:2017-04-11 01:07:19

标签: r plot

我一直在使用R只有一个月,所以请耐心等待。我写了并绘制了以下函数:

func.1 <- function(x) {(-log(x))/(1+x)}
plot(func.1, from = 0, to = 6)

哪个有效,但现在我正在尝试编写并绘制一个函数来近似导数与差商:

diff.quot <- function(x, h = .0001) {(func.1(x+h)-func.1(x))/h}
plot(diff.quot)

以上所有代码运行正常,直到我尝试更改绘图函数中的h值。我想用不同的h值绘制diff.quot 所有具有相同功能的,但我不能:

plot(diff.quot, from = 0, to = 6, h = .01)

运行此代码会给我以下警告:&#34;在doTryCatch中(return(expr),name,parentenv,handler):&#34; h&#34;不是图形参数&#34;。知道我做错了吗?

1 个答案:

答案 0 :(得分:2)

您应该使用curve代替plot,如下所示:

curve(diff.quot(x,h=0.01), from = 0, to = 6)

enter image description here