# How to find y given an x of this implicit equation

This really got me thinking and I honestly have no idea. I’m guessing we don’t need the modulus sign given that is a hint but why? We were given an initial value problem:

$$\frac{\mathrm d y}{\mathrm d x} = \frac{y\cos x}{1+2y^2}, \;\; y(0) = 1$$

and the following "solution":

$$\ln |y| + y^2 = \sin(x) + 1$$ In this case, we can't write the solution as an explicit function of $$x$$, i.e. as $$y = r(x)$$, and must instead leave it in implicit form. For a given value of $$x$$, how would you determine the value of $$y$$? Is the modulus operator necessary for this initial value problem?

• You actually haven't given enough context to tell whether the modulus operator is needed, because you did not share the initial value problem for which the implicit solution is stated. See this introduction to posting mathematical notation and review my edits to make sure I've not unintentionally changed your meaning. – hardmath Sep 26 at 15:20
• Welcome to math stack exchange ! We would need a numerical method like newton's method to find the solution(s). What do you mean with "modulus operator" ? – Peter Sep 26 at 15:39
• @Peter: I think "modulus operator" here means the absolute value (applied to $y$). – hardmath Sep 26 at 15:42
• What makes the exercise "useful" in reinforcing the material you are studying will be more apparent if you explain the context in which this came up. Perhaps you are taking a class in differential equations or numerical methods. In any case the context would be help to Readers to grasp your level of understanding and how we can help. – hardmath Sep 26 at 16:18
• It is only a class in differential equations I am taking. I have not done any numerical methods so far and they supposedly weren’t a prerequisite, would be useful though! Should mention it’s a third year module at university – Marina Calder Sep 26 at 16:24

## 3 Answers

If you have not done numerical methods so far (Regula Falsi, Newton Raphson &c.) then an approximate way is to paper plot the graph of (inverse) function and from it read off approximate $$y$$ for a given $$x:$$

$$x= \sin^{-1}( \log |y| +y^2-1)$$

The online graphing calculator Desmos can do this for us (click on image for larger size):

Keep in mind that by convention $$\sin^{-1}$$ here only returns $$x \in [-\pi/2,+\pi/2]$$. The two branches correspond to using the absolute value of $$y$$, but since the initial point $$(0,1)$$ is on the upper branch, the continued solution remains on that branch. Visualize the complete solution by reflecting that upper branch backward and forward to yield a periodic "wave".

• Thanks corrected sign typo. Would be nice if graph is included in answer, – Narasimham Sep 27 at 18:03
• Done. Revise, of course, the wording I've added to suit your own narrative purpose. – hardmath Sep 28 at 15:06
• Fine, thanks for the edit. – Narasimham Sep 28 at 19:35

Given your background, I'll make some suggestions about how one might try to solve:

$$\ln |y| + y^2 = \sin(x) + 1$$

for $$y$$ when $$x$$ is known.

There are many root finding algorithms, and since calculus knowledge is assumed in any differential equations course, Newton's method is not excluded as a possibility. First year calculus courses often make mention of it in connection applications of the derivative or (later on) with power series, etc.

But there is an approach you can test out with a spreadsheet application: reframe the root-finding problem as a fixed-point problem.

Here we have a left hand side that depends only on $$y$$ and a right hand side that depends only on $$x$$. So once argument $$x$$ is chosen, finding $$y$$ becomes a matter of solving $$f(y) = C$$ where $$C = \sin(x) + 1$$ and:

$$f(y) = \ln |y| + y^2$$

A fixed-point iteration comes about if we can rewrite $$f(y) = C$$ in the form:

$$y = g(y)$$

Then with a suitable "initial guess" $$y_0$$, one hopes that the sequence:

$$y_{k+1} = g(y_k)$$

will converge. If it does, and function $$g(y)$$ is continuous, then the limit of that iteration will satisfy $$y = g(y)$$ and hence (if we did the algebra correctly) also satisfy $$f(y) = C$$ as originally desired.

There are many ways to do this, and indeed Newton's method falls into this pattern of "root finding" too. With a bit of experience one learns that the goal is to choose a rewritten $$y = g(y)$$ so that $$g(y)$$ varies slowly with $$y$$. Indeed one measure of this is that $$|g'(y)| \lt 1$$ in the region where we seek a solution, and sometimes this "contraction mapping property" will come up in a differential equations class in the treatment of solutions to nonlinear ODEs (which the currently initial value problem gives us an example of).

In any event I'd propose putting the rapidly changing part of $$f(y)$$, the $$y^2$$ term, on one side of the equation and the slowly changing part on the other side, lumped with the "constant" term $$C = \sin(x) + 1$$:

$$y^2 = C - \ln |y|$$

Then take the square root of both sides:

$$y = \sqrt{C - \ln |y|\,}$$

There are some details to think about here, and these are connected with the side question of whether the absolute values around $$y$$ are really necessary. As the Comments below the Question have already started to sketch out, because the initial value $$y(0) = 1$$ is positive, it is conceivable that $$y(x)$$ will stay positive. If it does the absolute value of $$y$$ is just $$y$$, and the "modulus operator" is indeed unnecessary. A more rigorous, but still elementary treatment can be built, but this would take us on a detour from the present narrative.

Suffice it to say that choosing the positive square root above for $$y$$ is the right choice, and that while we can allow $$\ln y$$ to become negative (so the term under the square root remains nonnegative), we should avoid steps in the iteration where $$\ln y \gt 0$$ is so large that the term under the square root becomes negative. This affects our choice of starting guesses $$y_0$$ in particular.

So it is left as an exercise for the Reader to carry out a few iterations of the function $$g(y) = \sqrt{\sin(x) + 1 - \ln y \;}$$ using $$y_0 = 1$$ and a sampling of arguments for $$x$$. Note that because the right hand side $$\sin(x) + 1$$ is periodic function of $$x$$, the solution $$y(x)$$ will also be periodic. So it is only necessary to experiment with values $$x \in [0,2\pi]$$, or more restricted to the half-period $$x \in [-\pi/2,+\pi/2]$$.

I've done such an experiment, and it seems that when $$\sin(x) \ge 0$$ the iterations converge reliably. However for $$\sin(x)$$ sufficiently negative the term under the square roots becomes negative after a few iterations, which of course makes the iterations undefined.

For example, with $$x = -1$$ (or any argument differing by an integer multiple of $$2\pi$$, the iteration breaks down after about half a dozen steps. With $$x = -1.5$$ the iteration breaks down more quickly, after a couple of steps. This problem is mitigated by using more "accurate" starting guesses than the simple $$y_0 = 1$$, but it seems that this simple method is not reliably converging when $$C = \sin(x) + 1$$ is close to zero.

After thinking more carefully about this equation, I see that in the region where $$C = \sin(x) + 1$$ is small (positive), the term $$\ln y$$ is changing more rapidly than the term $$y^2$$. Hence I'm going to try the iteration "the other way around":

$$\ln y = C - y^2$$

$$y = e^{C - y^2}$$

In this approach an initial guess $$y_0 = 1$$ isn't appropriate when $$C$$ is small. In the extreme, when $$C = 0$$ we need $$y^2 + \ln y = 0$$, which occurs around $$y \approx 0.65$$. So I'll report my attempts with that $$y_0$$ as a starting value.

Using the alternative function iteration isn't particularly successful except very near $$C=0$$, although better starting guesses $$y_0$$ are an improvement when $$0\le C \lt 0.7$$ than the earlier $$y_0 = 1$$. The following graph (made with online graphing calculator Desmos) shows how the function $$f(y) = \ln |y| + y^2$$ behaves over the range $$C\in [0,2]$$:

With this insight I can see how the fixed point iteration can be improved, albeit the smoothness of this curve makes it clear to trained eyes that bisection, regula falsi, or even Newton's method would be well-behaved for the purpose of inverting this function.

• How is this question related to root finding arguements...? – Buraian Sep 26 at 18:05
• @Buraian: The OP was presented with an implicit solution to a nonlinear ODE (see the edit history of the Question if you find this not obvious in its current form) and asked "For a given value of x, how would you determine the value of y?" The implicit rather than explicit form is a reflection of the need for a numerical method to determine $y$ given $x$. – hardmath Sep 26 at 18:08
• I can’t thank you enough for such a detailed response, and something I can understand! – Marina Calder Sep 26 at 19:35
• Wish I could upvote you and this answer more than once – Marina Calder Sep 26 at 19:37

In terms of elementary function, it is sure that you must stay with the implicit form. Howver, sooner or later, you will learn that the solution is given by $$y=\sqrt{\frac 12 W\left(2 e^{2(1+ \sin (x))}\right)}$$ where $$W(.)$$ is Lambert function.

$$y$$ is maximum when $$x=\frac \pi 2+2k\pi$$ (at these points $$y_{max}\sim 1.3141$$; $$y$$ is minimum when $$x=\frac {3\pi} 2+2k\pi$$ (at these points $$y_{min}\sim 0.6529$$). So, the range is quite small for the possible values of $$y$$.

Beside strict numerical methods, you can make good approximations builiding the Talor expansions around the extrema.

For $$0 \leq x \leq \pi$$ use $$y=p-\frac{p }{2 \left(2 p^2+1\right)}\left(x-\frac{\pi }{2}\right)^2+\frac{p \left(2 p^4-p^2+2\right) }{12 \left(2 p^2+1\right)^3}\left(x-\frac{\pi }{2}\right)^4+O\left(\left(x-\frac{\pi }{2}\right)^6\right)$$ where $$p=\sqrt{\frac 12 W\left(2 e^4\right)}\sim \frac{4372}{3327}$$ This leads to a maximum absolute error of $$0.0025$$ at the bounds.

For $$\pi \leq x \leq 2\pi$$ use $$y=q+\frac{q }{2 \left(2 q^2+1\right)}\left(x-\frac{3 \pi }{2}\right)^2-\frac{q \left(2 q^4+5 q^2-1\right) }{12 \left(2 q^2+1\right)^3}\left(x-\frac{3 \pi }{2}\right)^4+O\left(\left(x-\frac{3 \pi }{2}\right)^6\right)$$ where $$q=\sqrt{\frac 12 W\left(2 \right)}\sim \frac{1868}{2861}$$ This leads to a maximum absolute error of $$0.0100$$ at the bounds.

All of the above would give $$\left( \begin{array}{ccc} x & \text{estimation} & \text{exact} \\ 0.0 & 0.99716 & 1.00000 \\ 0.2 & 1.06418 & 1.06548 \\ 0.4 & 1.12640 & 1.12691 \\ 0.6 & 1.18193 & 1.18210 \\ 0.8 & 1.22918 & 1.22922 \\ 1.0 & 1.26685 & 1.26686 \\ 1.2 & 1.29396 & 1.29396 \\ 1.4 & 1.30980 & 1.30980 \\ 1.6 & 1.31397 & 1.31397 \\ 1.8 & 1.30637 & 1.30637 \\ 2.0 & 1.28718 & 1.28718 \\ 2.2 & 1.25690 & 1.25692 \\ 2.4 & 1.21631 & 1.21638 \\ 2.6 & 1.16650 & 1.16674 \\ 2.8 & 1.10884 & 1.10953 \\ 3.0 & 1.04501 & 1.04667 \\ 3.2 & 0.98905 & 0.98048 \\ 3.4 & 0.91848 & 0.91365 \\ 3.6 & 0.85138 & 0.84913 \\ 3.8 & 0.79075 & 0.78992 \\ 4.0 & 0.73905 & 0.73886 \\ 4.2 & 0.69830 & 0.69827 \\ 4.4 & 0.66999 & 0.66999 \\ 4.6 & 0.65514 & 0.65514 \\ 4.8 & 0.65427 & 0.65427 \\ 5.0 & 0.66741 & 0.66741 \\ 5.2 & 0.69409 & 0.69407 \\ 5.4 & 0.73338 & 0.73320 \\ 5.6 & 0.78381 & 0.78309 \\ 5.8 & 0.84346 & 0.84145 \\ 6.0 & 0.90991 & 0.90547 \\ 6.2 & 0.98023 & 0.97218 \end{array} \right)$$

For sure, adding one more term in each expansion would give almost the exact results.