tags:

views:

27

answers:

2

I'm trying to draw sigmoid function using this code on scilab, but the result I got is not from the equation. what's wrong with my code?

x = -6:1:6; y = 1/(1+%e^-x)

y =

0.0021340  
0.0007884  
0.0002934  
0.0001113  
0.0000443  
0.0000196  
0.0000106  
0.0000072  
0.0000060  
0.0000055  
0.0000054  
0.0000053  
0.0000053  

http://en.wikipedia.org/wiki/Sigmoid_function

thank you so much

A: 

Try:

-->function [y] = f(x)
-->  y = 1/(1+%e^-x)
-->endfunction

-->x = -6:1:6;

-->fplot2d(x,f)

which yields: alt text

Bart Kiers
A: 

Your approach calculates the pseudoinverse of the (1+%e.^x) vector. You can verify by executing: (1+%e^-x)*y

Here are two things you could do:

x = -6:1:6; y = ones(x)./(1+%e.^-x)

This gives the result you need. This performs element-wise division as expected.

Another approach is:

x = -6:1:6    
deff("z = f(x)", "z = 1/(1+%e^-x)") 
// The above line is the same as defining a function- 
// just as a one liner on the interpreter.
y = feval(x, f)

Both approaches will yield the same result.

Aditya Sengupta