q = 6; # hardcoded Z = phi(X, q); w = linear_regression(Z, y); # Define the ranges of the grid u = linspace(-20, 30, 100); v = linspace(-20, 30, 100); # Initialize space for the values to be plotted z = zeros(length(u), length(v)); for i = 1:length(u) for j = 1:length(v) # Notice the order of j, i here! z(j, i) = map_feature(u(i), v(j), q) * w; end end x1 = X(:, 2); x2 = X(:, 3); plot(x1, x2, '.') hold on contour(u,v,z, [0, 0], 'LineWidth', 2) hold off