# Una ANIMAZIONE: clicca sul grafico e vedi che cosa succede
# (quando vuoi finire premi ESC; se vuoi cambia funzione)
par( mai = c(0.5,0.5,0.1,0.1) )
f <- function(x) 3*x^3-x^2+5*x-2
g <- function(x) eval(D(body(f),"x"))
x0 <- 2
a <- 0; b <- 2.5; c <- 0; d <- 50
while(1==1) {
plot(f,a,b); abline(h=0,v=0,lty=3,col="red")
points(x0,f(x0),pch=19); p <- locator(1)
xA <- round(p$x*10)/10
pend <- ifelse(xA==x0,g(x0),(f(xA)-f(x0))/(xA-x0))
points(xA,f(xA)); if(xA==x0) points(xA,f(xA),pch=19,col="red")
h <- function(x) (x-x0)*pend+f(x0)
plot(h,a,b,col="blue",add=TRUE)
text((a+b)/2,d-(d-c)/20,paste("pendenza = ",pend,sep=""))
locator(1)}

# Puoi fare le stesse cose azionando:
source("http://macosa.dima.unige.it/R/pend.txt")
# e battendo:
aiuto