## Example 1: even power of an interval containing zero: [0, 1], not [-1, 1].
interval(data.frame(x = c(-1, 1)), expression(x^2))
## Example 2: a nonlinear model, monotone in each variable:
## the vertices (seq = 2) give the exact range.
EXPR2 <- expression(Cf * sqrt((520 * H * P)/(M * (Temp + 460))))
H <- c(64, 65); M <- c(16, 16.2); P <- c(361, 365); Temp <- c(165, 170); Cf <- c(38.4, 38.5)
DAT2 <- makeDat(EXPR2)
interval(DAT2, EXPR2, seq = 2)
## Example 3: body mass index.
EXPR3 <- expression(m/h^2)
m <- c(79.5, 80.5); h <- c(1.795, 1.805)
DAT3 <- makeDat(EXPR3)
interval(DAT3, EXPR3)
## Example 4: minimum inside the interval. For x in [-2, 1], naive interval arithmetic gives
## [0, 4] - [-2, 1] + 1 = [0, 7] (or [-2, 7] if x^2 is computed as x * x);
## the true range is [0.75, 7].
EXPR4 <- expression(x^2 - x + 1)
x <- c(-2, 1)
DAT4 <- makeDat(EXPR4)
interval(DAT4, EXPR4, seq = 2, refine = FALSE) ## vertices and 0 only: [1, 7]
interval(DAT4, EXPR4, seq = 2) ## refined: [0.75, 7]
curve(x^2 - x + 1, -2, 1)
## Example 5: dependency problem. Naive interval arithmetic gives
## [0, 1] - [0, 1] = [-1, 1]; the true range is [0, 0.25].
EXPR5 <- expression(x - x^2)
x <- c(0, 1)
DAT5 <- makeDat(EXPR5)
interval(DAT5, EXPR5, seq = 2, refine = FALSE) ## vertices only: [0, 0]
interval(DAT5, EXPR5) ## [0, 0.25]
curve(x - x^2, 0, 1)
Run the code above in your browser using DataLab