# How do I implement the sigmoid function in Octave? [closed]

so given that the sigmoid function is defined as hθ(x) = g(θ^(T)x), how can I implement this funcion in Octave given that g = zeros(size(z)) ?

This will compute the sigmoid of a scalar, vector or matrix.

function g = sigmoid(z)
%   SIGMOID Compute sigmoid function
%   g = SIGMOID(z) computes the sigmoid of z.

% Compute the sigmoid of each value of z (z can be a matrix,
% vector or scalar).

SIGMOID = @(z) 1./(1 + exp(-z));

g = SIGMOID(z);

end

• Was using '/' in place of './'. My very very bad. Jun 17 '18 at 7:26
• You could just use g = 1 ./ (1 + exp(-z)); instead of creating this SIGMOID inside the sigmoid function. Oct 11 '18 at 3:01
• g= 1./ (1 + exp(-z)); careful about ./ divide had (dot sign) & parentheses of (1 + ...) is mandatory here, I spend mins debugging that. May 28 at 13:27