p <- c(sample(1:3, 1), sample(1:5, 1))
q <- c(sample((p[1] + 1):5, 1), sample(1:5, 1))
d <- abs(p - q)
sol <- round(c(sum(d), sqrt(sum(d^2)), max(d)), digits = 3)

Question

Given two points $p = (r p[1], r p[2])$ and $q = (r q[1], r q[2])$ in a Cartesian coordinate system:

Questionlist

Solution

The distances are visualized below in green ($d_1$), red ($d_2$), and blue ($d_\infty$).

par(mar = c(4, 4, 1, 1))
plot(0, type = "n", xlim = c(0, 6), ylim = c(0, 6), xlab = "x", ylab = "y")
grid(col = "slategray")
if(d[1] >= d[2]) {
  lines(c(p[1], q[1]), c(q[2], q[2]) - 0.05, lwd = 2, col = "blue")
} else {
  lines(c(p[1], p[1]) - 0.05, c(p[2], q[2]), lwd = 2, col = "blue")
}
lines(rbind(p, q), lwd = 2, col = "red")
lines(c(p[1], p[1], q[1]), c(p[2], q[2], q[2]), lwd = 2, col = "green")
points(rbind(p, q), pch = 19)
text(rbind(p, q), c("p", "q"), pos = c(2, 4))

Solutionlist

Meta-information

extype: cloze exsolution: r sol[1]|r sol[2]|r sol[3] exclozetype: num|num|num exname: Distances extol: 0.01



flaviobarros/exams documentation built on May 28, 2019, 8:39 p.m.