gpt4 book ai didi

R:绘制函数, "not a graphical parameter"

转载 作者:行者123 更新时间:2023-12-05 05:21:08 25 4
gpt4 key购买 nike

我使用 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)

在我尝试更改 plot 函数中的 h 值之前,上述所有代码都运行良好。我想绘制具有不同 h 值的 diff.quot 都具有相同的功能,但我不能:

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

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

最佳答案

你应该像这样使用 curve 而不是 plot:

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

enter image description here

关于R:绘制函数, "not a graphical parameter",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43335139/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com