#1 a)
x1 <- seq(-10, 10, by = 0.1)
## solve for x2
x2 <- 1 + 3 * x1
plot(x = x1, y = x2, type = 'l')
The hyperplane 1+3X1−X2=0 separates the plane into regions where the expression is positive below the line (red points) and negative above it (blue points).
#b)
plot(x = x1, y = x2, type = 'l')
points(x = c(-10, -5, 0, -2, -7),
y = c(30, 16, 1, 7, 10),
col = 'red')
points(x = c(-5, -3, 2, 7, 1),
y = c(0, -5, -10, 10, -5),
col = 'blue')
In the plot, the black line represents the hyperplane Points above the line (red points) satisfy 1+3X1−X2>0 Points below the line (blue points) satisfy 1+3X1−X2<0
#2 a)
x1 <- seq(-3, 1, by = 0.01)
x2 <- 2 - sqrt(4 - (1 + x1)^2)
x2m <- 2 + sqrt(4 - (1 + x1)^2)
# Plot the lower branch first
plot(x = x1, y = x2, type = "l", ylim = c(-1, 5),
xlab = "X1", ylab = "X2",
main = "(1 + X1)^2 + (2 - X2)^2 = 4")
# Plot the upper branch
lines(x = x1, y = x2m)
#b)
x1 <- seq(-3, 1, by = 0.01)
x2_lower <- 2 - sqrt(4 - (1 + x1)^2)
x2_upper <- 2 + sqrt(4 - (1 + x1)^2)
plot(x = x1, y = x2_lower, type = "l", ylim = c(-1, 5), xlab = "X1", ylab = "X2", main = "Nonlinear Decision Boundary")
lines(x = x1, y = x2_upper)
# 2(b) Add points
# Points inside the circle (<=4)
points(x = c(-1.5, -1, 0), y = c(2, 2.5, 1.5), col = "red", pch = 19)
# Points outside the circle (>4)
points(x = c(-3, -2.5, 1), y = c(4, -1, 5), col = "blue", pch = 19)
# Add legend
legend("topright", legend = c("<=4 (red points)", ">4 (blue points)"),
col = c("red", "blue"), pch = 19)