# Mathematical pendulum m l y'' + m g sin(y) = 0
pendel <- function(t, y) -sin(y[1])
sol <- newmark(pendel, 0, 4*pi, c(pi/4, 0))
plot(sol$t, sol$y[, 1], type="l", col="blue",
xlab="Time", ylab="Elongation/Speed", main="Mathematical Pendulum")
lines(sol$t, sol$y[, 2], col="darkgreen")
grid()
Run the code above in your browser using DataLab