R code that gives results like Wolfram Alpha for the expectation of a function of a random variable?
You can simulate one of these lines like this:
library(ggplot2)
X&lt;-rnorm(1000, 1, sqrt(4))
f&lt;-function(x) exp(-x*x)
df&lt;-data.frame(sample_size=seq_len(1000), sample_means=cumsum(f(X))/seq_len(1000))
ggplot(df, aes(x=sample_size, y=sample_means)) + 
geom_line() + theme_minimal() + labs(x=NULL, y=NULL)