My implementation (see below) gives the scalar value 3.18, which is not the right answer. The value should be 0.693. Where does my code deviate from the equation?
Here are the instructions to solve for the data to run the cost function method in Octave:
data = load('ex2data1.txt');
X = data(:, [1, 2]); y = data(:, 3);
[m, n] = size(X);
X = [ones(m, 1) X];
initial_theta = zeros(n + 1, 1);
[cost, grad] = costFunction(initial_theta, X, y);
Here is the link on ex2data, in this package there is data: data link.
The formula for the cost function is

Here is the code I am using:
function [J, grad] = costFunction(theta, X, y)
m = length(y); % number of training examples
% You need to return the following variables correctly
J = 0; %#ok<NASGU>
grad = zeros(size(theta)); %#ok<NASGU>
hx = sigmoid(X * theta)';
m = length(X);
J = sum(-y' * log(hx) - (1 - y')*log(1 - hx)) / m;
grad = X' * (hx - y) / m;
end
Here is the sigmoid function:
function g = sigmoid(z)
g = 1/(1+exp(-z));
end