Path: blob/master/Week 2/Programming Assignment-1/computeCostMulti.m
626 views
function J = computeCostMulti(X, y, theta)1%COMPUTECOSTMULTI Compute cost for linear regression with multiple variables2% J = COMPUTECOSTMULTI(X, y, theta) computes the cost of using theta as the3% parameter for linear regression to fit the data points in X and y45% Initialize some useful values6m = length(y); % number of training examples78% You need to return the following variables correctly9J = 0;1011% ====================== YOUR CODE HERE ======================12% Instructions: Compute the cost of a particular choice of theta13% You should set J to the cost.14%J = (1/2*m)*sum((X*theta-y)'*(X*theta-y));15%printf("Compute Cost\n");16%disp(J);17predictions = X * theta;18sqrErrors = (predictions - y).^2;19J = (1/(2*m)) * sum(sqrErrors);20printf("The size of J is\n");21disp(size(J));22printf("Compute Cost\n");23disp(J);24% =========================================================================2526end272829