M HYPE SPLASH
// general

Find X for Y on a sigmoid curve / function

By Sarah Scott
$\begingroup$

Note: i write this script in javascript. But any knowledge on how to produce this function is welcome!

In the following graph you see the s-curve or sigmoid curve. The blue line shows my value Y (y-axis) (y=75). The curve has a scale of [0,0] to [100,100]. So y is always from 0 to 100.

scurve illustrating the issue

I am trying to plot the red dot on the scurve where the blue line intersects. (so find the X value for a Y value.

My function to draw the scurve is as follows:

function sigmoid(x)
{ return 1 / (1 + Math.pow(Math.exp(1), -x));
}
for (let z = -6; z <= 6; z += .05) { let sigmoidX = x1 + (x2 - x1) * ((z + 6) / 12); let sigmoidY = y1 + (y2 - y1) * sigmoid(z);
}

Now i need a function to get a X/Y value when Y is known and X is unknown

function getPointOnCurve(y) { ... code to calc x return x;
}

UPDATE:

 const points = [ { x: 0, y: 0 }, { x: 100, y: 100 } ];
function getSigmoid(points) { let x1 = points[0].x; let x2 = points[1].x; let y1 = points[0].y; let y2 = points[1].y; let PathData = []; for (let z = -6; z <= 6; z += .05) { let sigmoidX = x1 + (x2 - x1) * ((z + 6) / 12); let sigmoidY = y1 + (y2 - y1) * sigmoid(z); var vector = new Vector2(sigmoidX, sigmoidY); PathData.push(vector); } return PathData;
}
$\endgroup$ 2

1 Answer

$\begingroup$

As I understand, you have a curve of the form$$\tag{1} y_1 = \frac{100}{1+e^{-x}} $$and a line$$ y_2 = 75 $$Now, you want to calculate their intersection point. This can be done easily by hand. First, equate the two to get$$ y_1 = y_2 \qquad \Rightarrow \qquad \frac{100}{1+e^{-x}} = 75 $$We can solve the $x$-coordinate quite easily. Multiply both sides by $\frac{1+e^{-x}}{75}$ to get$$ \frac{100}{1+e^{-x}}\left( \frac{1+e^{-x}}{75} \right) = 75 \cdot \left( \frac{1+e^{-x}}{75} \right) $$As you probably see, a lot of the terms cancel out and we get$$ \frac{100}{75} = 1 + e^{-x} $$We are close to the solution. Subtract $1$ from both sides to get$$ \frac{100}{75} -1 = e^{-x} $$or $\frac{1}{3}= e^{-x}$. This equation can be solved by taking the natural logarithm on both sides. The result is$$ \ln{\left( \frac{1}{3} \right)} = -x $$Remembering the properties of logarithms, we get $\ln{\frac{1}{3}} = - \ln{3}$and therefore$$ x = \ln{3} \approx 1.0986 $$Therefore, the coordinates are

$$ (x,y) = (\ln{3}, 75) $$

You can test if this is the correct answer by inserting $x=\ln{3}$ into Equation (1)

$\endgroup$ 10

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy