% Read in data dat = textread('hw1.dat'); % X is the design matrix X = dat(:,1:2); % y_bar is the vector of desired outputs y_bar = dat(:,3); %Plot the input features close all; figure(1); plot3(X(:,1),X(:,2),y_bar,'.'); xlabel('x1'); ylabel('x2'); zlabel('y'); grid on; title('Input data'); %Construct a "fake" error surface and generate a contour plot theta1 = -10:10; theta2 = -10:10; theta_grid = ndgrid(theta1,theta2); for i = 1:length(theta1), for j = 1:length(theta2), %Set the error to be the distance from the origin J(i,j) = theta1(i)^2 + theta2(j)^2; end end figure(2); contour(theta1,theta2,J); title('Error surface');