Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: plotting a function, "not a graphical parameter"

Tags:

plot

r

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?

like image 437
chidimma-nzerem Avatar asked Apr 23 '26 18:04

chidimma-nzerem


1 Answers

You should use curve instead of plot like this:

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

enter image description here

like image 165
Pierre Lapointe Avatar answered Apr 25 '26 07:04

Pierre Lapointe