Given the function $y=\sin x$ defined over the region $-\pi \leq x \leq \pi$, I need to implement a "do loop" such that I sweep over 100 or so points $-1 \leq y \leq 1$ and find precisely the two $x$ values which map to this $y$ under $\sin x$. For example, with $y=1/8$, I have the following code:
NSolve[Sin[x] == 1/8 && -Pi <= x <= Pi, x, WorkingPrecision -> 20]
which outputs:
{{x -> 0.12532783116806539687}, {x -> 3.0162648224217278416}}
Given these two points, call them $x_{1}$ and $x_{2}$ I want to plot a point $f(1/8) = |x_{1}-x_{2}|$. In other words, I want to sweep over 100 or so $-1 \leq y \leq 1$ and plot $|x_{1}-x_{2}|$ at each of these points.
So, I'm wondering what the most efficient way to do this would be? In particular, I'm worried about storing the variables
{{x -> 0.12532783116806539687}, {x -> 3.0162648224217278416}}
How can I store these variables within the loop or how would I call them? Perhaps the loop can output an array of my $y$ values and an array of $|x_{1}-x_{2}|$ values and I can trivially plot them from there?
Edit
So for my actual case of interest I have a function which essentially looks similar in form to $\sin x$, but is messier:
$$\lambda(x) = -\frac{1}{2}\frac{\theta'_{3}(\pi\, x\ |\ \tau)}{\theta_{3}(\pi\, x\ |\ \tau)}$$
Where these are the Jacobi theta functions. Mathematica takes the input EllipticTheta[3, Pi*x, Exp[I*Pi*tau]]. Like I said, this behaves similarly to $\sin$ over the region $[-1/2,1/2]$. So, what I'd like to do is, for a given $\tau$ that won't change, sweep through values $a \in [-\lambda_{\rm{max}}, \lambda_{\rm{max}}]$ and for each such value, find the two $x$ values which map to $a$ under $\lambda(x)$.
Given these two numbers, call them $x_{1}$ and $x_{2}$, I then would like to compute,
$\quad \quad \wp(2x_{1} + 1 + \tau \ | \ 1,\, \tau)-\wp(2x_{2}+1+\tau \ | \ 1,\, \tau)$
I'm getting comfortable with NSolve and FindMax, but sweeping over 100 or so $a \in [-\lambda_{\rm{max}},\, \lambda_{\rm{max}}]$ and storing and plotting, that's way over my head!




-(1/2)*(EllipticThetaPrime[3, Pi*x, Exp[I*(1+I)*Pi]])/(EllipticTheta[3, Pi*x, Exp[I*(1+I)*Pi]])– Benighted Jul 28 '15 at 02:13