# Sigmoid Function not working as expected

**URL:** <https://cl.desmos.com/t/sigmoid-function-not-working-as-expected/5301>\
**Category:** Questions\
**Tags:** simplefunction\
**Created:** [January 1, 2024, 12:42pm UTC](https://cl.desmos.com/t/sigmoid-function-not-working-as-expected/5301 "2024-01-01T12:42:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sharmila](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/sharmila/32/4712_2.png) [@Sharmila](https://cl.desmos.com/u/Sharmila)\
**Post date:** [January 1, 2024, 12:42pm UTC](https://cl.desmos.com/t/sigmoid-function-not-working-as-expected/5301/1 "2024-01-01T12:42:38Z")

</div>

I want to write the below function in computation layer  
SIGMOID Function:  
y = 1 / ( 1 + e^( - x))

The code i wrote is:  
function(“f”): simpleFunction(“1/(1+2.7)^(-x)”)

The output is always showing undefined , Not sure what is wrong.

Expected Output range is [0 to 1]

Can anyone help me solve this

---

<div class="post-metadata">

**Author:** ![Daniel\_Wekselgreene](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_wekselgreene/32/1819_2.png) [@Daniel\_Wekselgreene](https://cl.desmos.com/u/Daniel_Wekselgreene)\
**Post date:** [January 1, 2024, 6:44pm UTC](https://cl.desmos.com/t/sigmoid-function-not-working-as-expected/5301/2 "2024-01-01T18:44:42Z")

</div>

Yeah, it’s not properly formatted in latex. The easiest way is to type the function in the calculator, copy it, and then paste it into CL. All the formatting will be done perfectly that way.

---

<div class="post-metadata">

**Author:** ![Sharmila](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/sharmila/32/4712_2.png) [@Sharmila](https://cl.desmos.com/u/Sharmila)\
**Post date:** [January 2, 2024, 3:49am UTC](https://cl.desmos.com/t/sigmoid-function-not-working-as-expected/5301/3 "2024-01-02T03:49:55Z")

</div>

Thanks It worked!

I have one more query, It always rounds off my output to 1. Is there a way I can make it to display upto 2 decimal places.

finalVal = “0.996”  
number(“p\_{out}”): numericValue(finalVal)

This gives out 1 instead of 0.996

---

<div class="post-metadata">

**Author:** ![Daniel\_Wekselgreene](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_wekselgreene/32/1819_2.png) [@Daniel\_Wekselgreene](https://cl.desmos.com/u/Daniel_Wekselgreene)\
**Post date:** [January 2, 2024, 5:22am UTC](https://cl.desmos.com/t/sigmoid-function-not-working-as-expected/5301/4 "2024-01-02T05:22:51Z")

</div>

You might have more luck defining it as a function and using the evaluateAt method.

f = simpleFunction(latex string)  
Val = f.evaluateAt(input value)

I’m not sure about rounding. What you are trying to do may be more easily accomplished inside a graph component. You can definitely use the round(value, places) function in the graph. You can pass inputs into the graph by sinking a number into a variable and then you can pull outputs from the graph using the variables as sources. If you don’t want the graph to be seen you can just set hidden to true in its CL.

If you want an example let me know.

---

<div class="post-metadata">

**Author:** ![Sharmila](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/sharmila/32/4712_2.png) [@Sharmila](https://cl.desmos.com/u/Sharmila)\
**Post date:** [January 2, 2024, 2:22pm UTC](https://cl.desmos.com/t/sigmoid-function-not-working-as-expected/5301/5 "2024-01-02T14:22:29Z")

</div>

Thanks for the response, It got fixed!

As you mentioned, I simply used round(value,decimalplaces) around the value. Thanks for the support
