sigmoid.m

g = 1./(1+exp(-z));

costFunction.m

J = 1./m*(-y'*log(sigmoid(X*theta)) - (1-y)'*log(1-sigmoid(X*theta)));
grad = 1/m * X'*(sigmoid(X*theta) - y);

predict.m

J = 1./m*(-y'*log(sigmoid(X*theta)) - (1-y)'*log(1-sigmoid(X*theta)));
grad = 1/m * X'*(sigmoid(X*theta) - y);

 costFunctionReg.m

[J, grad] = costFunction(theta, X, y);

J = J + lambda/(2*m)*(sum(theta.^2) - theta(1).^2); %no need theta 1
grad = grad + lambda/m*theta;
grad(1) = grad(1) - lambda/m*theta(1);