2
votes

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?

1
Looks like it's an issue with having the second argument h to diff.quot. Try removing the h = .01 from the plot call (diff.quot will use the default value h = .0001). - vincentmajor
@vincentmajor But how can I plot diff.quot with different h values without making additional functions? I just wanna use the same function to make multiple plots. - chidimma-nzerem

1 Answers

2
votes

You should use curve instead of plot like this:

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

enter image description here