Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n <- 51 # Number of interpolation points
- k.1 <- floor(n * 2/3) # Width of the left-hand interval
- k.2 <- n - k.1 # ............ right-hand interval
- x <- seq(0, 1, length.out=n) # x coordinates
- set.seed(17)
- # Generate random values of the second derivative that are first negative,
- # then positive. Modify to suit.
- y.2 <- (c(runif(k.1, -1, 0), 0.5*runif(k.2, 0, 1))) * abs(cos(3*pi * x)) +
- c(rep(-.1, k.1), rep(.5,k.2))
- # Recover the first derivative and then the transformation. Control the
- # minimum slope of the transformation.
- y.1 <- cumsum(y.2)
- y.1 <- y.1 - min(y.1) + 0.005 * diff(range(y.1))
- y <- cumsum(y.1)
- y <- (y - y[1]) / (y[n] - y[1]) # Normalize the transformation
- #
- # Plot the graphs.
- par(mfrow=c(1,3))
- plot(x, y.2, type="l", bty="n", main="Second derivative")
- points(x, y.2, pch=20, cex=0.5)
- abline(h=0, col="Red", lty=3)
- plot(x, y.1, type="l", bty="n", lwd=2, main="First derivative")
- abline(h=0, col="Red", lty=3)
- plot(x, y, type="l", lwd=2, main="Transformation")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement