I'm trying to plot a simulation of a differential equation versus its exact analytical solution, but keep getting "Error in FUN(X[[i]], ...) : object 'value' not found", even though it is declared just the line before! It seems like I have made a silly mistake in some place, but I cannot find it at all. Plus, it doesnt recognized the labels I specified, giving a "unexpected symbol error". Thanks in advance,
require(ggplot2)
N<-500
T<-3
dt<-T/N
X <-c()
X[1] <-4
B<-numeric(N+1)
tt<-seq(0,T,length=N+1)
for(t in seq(2,N+1)){
B[t] <- B[t-1]+rnorm(1)*sqrt(dt)
}
for(i in seq(2,N+1)){
X[i] <- X[i-1]+2*B[i-1]*(B[i]-B[i-1])+dt
}
S <- as.data.frame(rep(X[1],501) + B^2)
names(S) <- (c('value','t','Solutions') labels=c("Simulation", "Exact Solution") )
ggplot(data = S, aes(x = t, y = value, colour = variable)) + geom_line()
P.E:Sorry if this is a way to stupid question, I'm a noob using R, but I'm force to use it for work realted things.