tic <- function(x) {sec <-proc.time()[3]; while(proc.time()[3]<sec+x) sec<-sec} # passano x sec
f <- function(x) x^2
plot(f,0,3,col="blue"); abline(h=1,col="green4"); points(1,f(1),col="blue")
tx<- c(1,2,3); ty<- c(2,3,4,5,6,7,8,9); abline(h=ty,col="grey60",lty=3);abline(v=tx, col="grey60",lty=3)
arrows(-0.5,0,3.1,0,length=0.1); arrows(0,-0.5,0,9.2,length=0.1)
text(1.4,8.7,expression("le rette per i punti con x=1 x=1+h"),col="red")
text(2.3,1.5,expression("p = pendenza")); text(1.4,0.5,expression("y = x^2"),col="blue")
# traccio per dx=2 la retta per i punti di y=x^2 con x=1, x=1+dx e ne calcolo la pendenza p
dx<- 2; p<- (f(1+dx)-f(1))/dx; points(1+dx,f(1+dx),col="blue")
g<- function(x) (x-1)*p+f(1); plot(g,0,3,add=TRUE, col="red")
text(0.5,8,bquote(p==.(p))); text(1.5,8,bquote(h==.(dx)))  # faccio lo stesso per dx=1
tic(5); dx<- 1; p<- (f(1+dx)-f(1))/dx; points(1+dx,f(1+dx),col="blue"); plot(g,0,3,add=TRUE,col="red")
text(0.5,7.2,bquote(p==.(p))); text(1.5,7.2,bquote(h==.(dx)))  # proseguo con dx piu' piccolo
tic(5); dx<- 0.1; p<- (f(1+dx)-f(1))/dx; points(1+dx,f(1+dx),col="blue"); plot(g,0,3,add=TRUE,col="red")
text(0.5,6.4,bquote(p==.(p))); text(1.5,6.4,bquote(h==.(dx)))  # proseguo solo numericamente con dx via via piu' piccolo
tic(5); dx<- 0.01; p<- (f(1+dx)-f(1))/dx
text(0.5,5.6,bquote(p==.(p)),col="blue"); text(1.5,5.6,bquote(h==.(dx)),col="blue")
tic(1); dx<- 0.001; p<- (f(1+dx)-f(1))/dx
text(0.5,4.8,bquote(p==.(p)),col="blue"); text(1.5,4.8,bquote(h==.(dx)),col="blue")
tic(1/2); dx<- 0.0001; p<- (f(1+dx)-f(1))/dx
tic(1/2); text(0.5,4.2,expression(...),col="blue");text(1.5,4.2,expression(...),col="blue")