function J = computeCostMulti(X, y, theta) m = length(y); % number of training examples J = 0; for i = 1:m J = J + (X(i,:) * theta - y(i,1)) ^ 2 end; J = J / (2 * m); end
[ML] CostFunction [Octave code]
原文:http://www.cnblogs.com/KennyRom/p/6523381.html