Reputation: 33
I've been using R for only a month, so bear with me. I wrote and plotted the following function:
func.1 <- function(x) {(-log(x))/(1+x)}
plot(func.1, from = 0, to = 6)
which worked, but now I am trying to write and plot a function to approximate the derivative with the difference quotient:
diff.quot <- function(x, h = .0001) {(func.1(x+h)-func.1(x))/h}
plot(diff.quot)
All of the above code runs fine until I try to change the value of h in the plot function. I want to plot diff.quot with different h values all with the same function, but I can't:
plot(diff.quot, from = 0, to = 6, h = .01)
Running this code gives me the following warning: "In doTryCatch(return(expr), name, parentenv, handler) : "h" is not a graphical parameter". Any idea what I'm doing wrong?
Upvotes: 3
Views: 4888
Reputation: 16277
You should use curve
instead of plot
like this:
curve(diff.quot(x,h=0.01), from = 0, to = 6)
Upvotes: 2