Search code examples
octavesubscriptsigmoid

Writing the sigmoid function in octave and calculating sigmoid of 0 and negative numbers


I am a beginner to machine learning and octave. I am trying to write a code in octave that would calculate the sigmoid function g(z)=g(z)=1./(1+exp(-(z)));

When I try to find g(0) or g(-5) I get this error message:error: g(-5): subscripts must be either integers 1 to (2^63)-1 or logicals.

How do I resolve this, please?

Thanks so much in advance, for your help.


Solution

  • I have no clue why you encountered that error. When I tried the code below, it seems working well

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

    Example

    >> g(-5)
    ans =  0.0066929
    >> g(0)
    ans =  0.50000
    >> g(5)
    ans =  0.99331