Newton's method gradient and hessian formulation difficulties

Logistic regression Newton's Method Newton Method Lecture II

In this picture the logistic regression cost function , Newtons Method and gradient and Hessian is defined. How to get this function that is also defined by the video tutorial link.

H is a hypothesis function and as per this problem h is define by

In Matlab h is define as follows

% Initialize fitting parameters
theta = zeros(n+1, 1);

% Define the sigmoid function
g = inline('1.0 ./ (1.0 + exp(-z))');
% Calculate the hypothesis function
z = x * theta;
h = g(z);
% The formulas below are equivalent to the summation formulas
% given in the picture.

grad = (1/m).*x' * (h-y);