开发者

(scilab) x = [-6,6] y = 1/(1+%e^-x) why it doesn't work?

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


Try:

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

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

-->fplot2d(x,f)

which yields:

(scilab) x = [-6,6] y = 1/(1+%e^-x) why it doesn't work?


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.


With Scilab ≥ 6.1.1, simply

x = (-6:1:6)';
plot(x, 1./(1+exp(-x)))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜