polyFeatures <- function(X, p) { # Maps X (1D vector) into the p-th power # # X_poly <- polyFeatures(X, p) takes a data matrix X (size m x 1) and # maps each example into its polynomial features where # X_poly[i, ] <- [X[i] X[i].^2 X[i].^3 ... X[i].^p] # # You need to return the following variables correctly. X_poly <- matrix(0, nrow = ifelse(!is.null(nrow(X)), nrow(X), length(X)), ncol = p) # ======================= YOUR CODE HERE ======================= # Instructions: Given a vector X, return a matrix X_poly where the p-th # column of X contains the values of X to the p-th power. # # # ============================================================== return(X_poly) }