Sunday, July 19, 2009

Exponential density 2

Think of e as a function (rather than the irrational number 2.71828...).

In R:

e <- function(x) { 2.71828**(x) }
plot(e,0,5,lwd=10,col='gray70')
plot(exp,0,5,lwd=2,col='red',add=T)




Then, e can be defined as the function whose derivative is itself. To see this:

plot(exp,0,5,lwd=5,xlim=c(0,5),ylim=c(0,75))
par(lwd=2)
colors=c('blue','darkgreen','red','magenta')

f <- function(x) {
y=exp(x)
points(x,y,col=colors[x],pch=16,cex=2)
lines(c(x-1,x+1),c(y-y,y+y),
col=colors[x]) }
for (i in 1:4) f(i)




What did we do? First, we plotted the exponential function exp between 0 and 5 (heavy black line). Then, for each x in the series 1:4, we calculated y=exp(x) and plotted the point x,y in color. At the same time, we constructed a line with slope (y+y)/2 = y, passing through x,y. It is clear that the slope of the curve is equal to the value of the function at that point.

Another fun way to see this is to look at the infinite series for ex:



Can you see that the derivative with respect to x of this series is identical to the series itself?

Using simple calculus (the chain rule), we can also show that



Looking at the probability density function (pdf) for the exponential distribution,



and cumulative distribution function, we confirm that the pdf is the derivative of the cdf, as it should be. The cdf is: