# Create x1 values
x1 <- seq(-10, 10, by = 0.1)
# Calculate x2 for 1 + 3X1 - X2 = 0 --> X2 = 1 + 3*X1
x2 <- 1 + 3 * x1
# Plot the first hyperplane
plot(x1, x2, type = "l", col = "blue", lwd = 2,
xlab = "X1", ylab = "X2",
main = "Hyperplane: 1 + 3X1 - X2 = 0",
xlim = c(-10, 10), ylim = c(-10, 10))
# Add horizontal and vertical zero lines for better view
abline(h = 0, v = 0, lty = 3)
The plotted blue line represents the hyperplane 1 + 3X1 - X2 = 0, rearranged as X2 = 1 + 3X1.
Below the blue line: 1 + 3X1 - X2 > 0
Above the blue line: 1 + 3X1 - X2 < 0
Thus, points below the line satisfy the inequality 1 + 3X1 - X2 > 0, and points above the line satisfy 1 + 3X1 - X2 < 0.
# x1 is already defined
# Calculate x2 for the second hyperplane: -2 + X1 + 2X2 = 0 --> X2 = (2 - X1) / 2
x2_second <- (2 - x1) / 2
# Plot the first hyperplane again
plot(x1, x2, type = "l", col = "blue", lwd = 2,
xlab = "X1", ylab = "X2",
main = "Hyperplanes: 1 + 3X1 - X2 = 0 and -2 + X1 + 2X2 = 0",
xlim = c(-10, 10), ylim = c(-10, 10))
# Add the second hyperplane
lines(x1, x2_second, col = "red", lwd = 2, lty = 2)
# Add legend
legend("topright", legend = c("1 + 3X1 - X2 = 0", "-2 + X1 + 2X2 = 0"),
col = c("blue", "red"), lty = c(1, 2), lwd = 2)
# Add horizontal and vertical zero lines
abline(h = 0, v = 0, lty = 3)
We plotted two hyperplanes on the same graph:
Both hyperplanes divide the two-dimensional space into regions where the given expressions are either positive or negative.
# Create a sequence of angles from 0 to 2*pi
theta <- seq(0, 2*pi, length.out = 300)
# Center of the circle
center_x <- -1
center_y <- 2
# Radius of the circle
radius <- 2
# Parametric equations for circle
x1 <- center_x + radius * cos(theta)
x2 <- center_y + radius * sin(theta)
# Plot the circle
plot(x1, x2, type = "l", lwd = 2, col = "blue",
xlab = "X1", ylab = "X2",
main = "Curve: (1 + X1)^2 + (2 - X2)^2 = 4",
asp = 1, xlim = c(-5, 5), ylim = c(-2, 6)) # 'asp=1' makes it a proper circle
# Add center point
points(center_x, center_y, pch = 19, col = "red")
text(center_x, center_y, labels = "( -1, 2 )", pos = 4, col = "red")
The curve \((1 + X_1)^2 + (2 - X_2)^2 = 4\) represents a circle centered at \((-1, 2)\) with a radius of 2. All points lying exactly on this curve satisfy the equality.
# Part (2b) - Indicate the regions inside and outside the circle
# Create a grid of points
x1_vals <- seq(-6, 4, length.out = 200)
x2_vals <- seq(-2, 7, length.out = 200)
grid <- expand.grid(X1 = x1_vals, X2 = x2_vals)
# Compute (1 + X1)^2 + (2 - X2)^2 for each point
grid$val <- (1 + grid$X1)^2 + (2 - grid$X2)^2
# Plotting
plot(x1, x2, type = "l", lwd = 2, col = "blue",
xlab = "X1", ylab = "X2",
main = "Regions for (1 + X1)^2 + (2 - X2)^2",
asp = 1, xlim = c(-6, 4), ylim = c(-2, 7))
# Shade inside the circle (val <= 4) with light blue points
points(grid$X1[grid$val <= 4], grid$X2[grid$val <= 4], pch = ".", col = "lightblue")
# Shade outside the circle (val > 4) with pink points
points(grid$X1[grid$val > 4], grid$X2[grid$val > 4], pch = ".", col = "pink")
# Re-draw the main circle
lines(x1, x2, lwd = 2, col = "blue")
# Add center
points(center_x, center_y, pch = 19, col = "red")
text(center_x, center_y, labels = "( -1, 2 )", pos = 4, col = "red")
# Add legend
legend("topright", legend = c("Inside: <= 4", "Outside: > 4"),
col = c("lightblue", "pink"), pch = 15)
The region inside the circle, where \((1 +
X_1)^2 + (2 - X_2)^2 \leq 4\), is shaded in light blue.
The region outside the circle, where \((1 +
X_1)^2 + (2 - X_2)^2 > 4\), is shaded in pink. The blue curve
itself represents the boundary where \((1 +
X_1)^2 + (2 - X_2)^2 = 4\).
We classify an observation as blue if \((1+X_1)^2 + (2-X_2)^2 > 4\), and as red otherwise.
After calculating:
The decision boundary is not linear in terms of \(X_1\) and \(X_2\) because it forms a circle.
However, if we redefine variables to include \(X_1\), \(X_2\), \(X_1^2\), and \(X_2^2\), the boundary becomes a linear
combination of these terms.
Expanding \((1+X_1)^2 + (2-X_2)^2 = 4\)
gives:
\[ 1 + 2X_1 - 4X_2 + X_1^2 + X_2^2 = 0 \]
Thus, the boundary is linear in the new set of variables \((X_1, X_2, X_1^2, X_2^2)\).