Octave 我的倍频程函数返回;ans=0“-Coursera机器学习第2周问题

Octave 我的倍频程函数返回;ans=0“-Coursera机器学习第2周问题,octave,Octave,我目前正在学习Andrew Nguyen的coursera机器学习课程,我将在第2周学习。对于成本函数分配,我的函数在应该返回“ans=32.07: 我的代码如下(变量已在命令窗口中定义): 我认为您缺少文件顶部的函数声明。请您的问题包括完整(但最小!)代码,包括如何调用函数。我认为您缺少文件顶部的函数声明。请您的问题包括完整(但最小!)代码,包括如何调用函数。 %COMPUTECOST Compute cost for linear regression % J = COMPUTECOST

我目前正在学习Andrew Nguyen的coursera机器学习课程,我将在第2周学习。对于成本函数分配,我的函数在应该返回“ans=32.07: 我的代码如下(变量已在命令窗口中定义):


我认为您缺少文件顶部的函数声明。请您的问题包括完整(但最小!)代码,包括如何调用函数。我认为您缺少文件顶部的函数声明。请您的问题包括完整(但最小!)代码,包括如何调用函数。
%COMPUTECOST Compute cost for linear regression
%   J = COMPUTECOST(X, y, theta) computes the cost of using theta as the
%   parameter for linear regression to fit the data points in X and y

% Initialize some useful values
% number of training examples
m = length(y);
% You need to return the following variables correctly 
J =0;

% ====================== YOUR CODE HERE ======================

% Instructions: Compute the cost of a particular choice of theta
%               You should set J to the cos
h = X * theta;
J = (1/(2m)*(sum(h-y).^2));

% =========================================================================

end