3
$\begingroup$

When you solve the IVP

   DSolve[{y'[x] == 2*Log[y[x]/x], y[4] == 7}, y[x], x]

It results in

$$\text{Solve}\left[\displaystyle \int _4^{\dfrac{y(x)}{x}}\frac{1}{K[1]-2 \log (K[1])}dK[1]=\int _4^{\frac{7}{4}}\dfrac{1}{K[1]-2 \log (K[1])}dK[1]-\log (x)+\log (4),y(x)\right]$$

How should that result to be used?

Is there some way to get a $y(x)$ result from that output?

$\endgroup$
1
  • 1
    $\begingroup$ That means, Mathematica evaluates an implicit solution, which should be solved for y[x] $\endgroup$ Commented Oct 20, 2022 at 15:29

2 Answers 2

3
$\begingroup$

When Mathematica returns solution to ode with Solve in it, it means it could not solve something internally to give an explicit solution, most likely it was an integral it got stuck on.

To see this is the case, you can solve it by hand:

Solve \begin{gather*} \boxed{y^{\prime}=2 \ln \left(\frac{y}{x}\right)} \end{gather*} Since this ode is homogeneous, it can be converted to a separable ODE using the substitution $u=\frac{y}{x}$, or $y=ux$. Hence $$ \frac{ \mathop{\mathrm{d}y}}{\mathop{\mathrm{d}x}}= \frac{ \mathop{\mathrm{d}u}}{\mathop{\mathrm{d}x}}x + u $$ Therefore the ode becomes \begin{align*} \frac{\mathop{\mathrm{d}u}}{\mathop{\mathrm{d}x}} x + u &= 2 \ln \left(u\right) \\ \frac{\mathop{\mathrm{d}u}}{\mathop{\mathrm{d}x}} &= \frac{1}{x} \left(2 \ln \left(u\right)-u\right)\\ \frac{\mathop{\mathrm{d}u}}{\mathop{\mathrm{d}x}} &= f(x) f(u) \end{align*} Which is now separable in $u$ where $f(x)=\frac{1}{x}$ and $g(u)=2 \ln \left(u \right)-u$. Therefore integrating gives \begin{align*} \int \frac{1}{2 \ln \left(u \right)-u}\mathop{\mathrm{d}u} &= \int \frac{1}{x}\mathop{\mathrm{d}x}\\ \int \frac{1}{2 \ln \left(u \right)-u}\mathop{\mathrm{d}u} &= \ln \left(x \right)+c_{1} \end{align*} There is no antiderivative for the left side above. In this case it is written as \begin{align*} \int_{0}^{u} \frac{1}{2 \ln(k)-k}\, dk &= \ln(x)+c_{1} \end{align*} Where $k$ is the integration variable. $u$ in the above solution is replaced back by $y$ using $u=\frac{y}{x}$ which results in \begin{align*} \int_{0}^{\frac{y}{x}} \frac{1}{2 \ln(k)-k}\, dk &= \ln(x)+c_{1}\tag{1} \end{align*} Applying initial conditions $y(4) = 7$ to the above gives \begin{align*} \int_{0}^{\frac{7}{2}} \frac{1}{2 \ln(k)-k}\, dk &= \ln(4)+c_{1} \end{align*} Hence \begin{align*} c_{1} = \int_{0}^{\frac{7}{2}} \frac{1}{2 \ln(k)-k}\, dk - \ln(4) \end{align*} Substituting this back in (1) gives the solution given by Mathematica \begin{align*} \int_{0}^{\frac{y}{x}} \frac{1}{2 \ln(k)-k}\, dk &= \ln(x)+ \left(\int_{0}^{\frac{7}{2}} \frac{1}{2 \ln(k)-k}\, dk - \ln(4) \right) \tag{2} \end{align*}

Btw, the lower limit of the integral is not important.

But the important thing, is that now you see the problem. To get $y$, you need to solve the integral of the form $\int \frac{1}{2 \ln(k)-k}\, dk$ which does not have antiderivative, at least Mathematica could not find it.

So basically Mathematica is saying, if you can solve this equation, then you got your $y(x)$ solution. I also tried this in Maple, and it gave same solution, all due to the problem of not able to do the integration step in the middle. Nothing can be done about this really.

$\endgroup$
2
  • $\begingroup$ Thanks. So, in this case, should you just resort to numerical methods and ignore this solution? $\endgroup$
    – Moo
    Commented Oct 20, 2022 at 16:30
  • 1
    $\begingroup$ If you want a solution you can use and plot and so on, then yes, try numerical Numerical can solve almost anything well posed. For an analytical solution, the above is the best you can get. There is no explicit solution for $y(x)$ only implicit. $\endgroup$
    – Nasser
    Commented Oct 20, 2022 at 16:54
2
$\begingroup$

Extended Comment rather than answer

TL;DR An implicit equation can be interesting for an analysis of the function's characteristics. There are some use cases where it might be better than using NDSolve but I do not know of many scenarios like that. For this particular implicit function, I did not find much that one could use. As such, the following text does not contain anything particularly interesting and is kind of an extended comment

The implicit solution given by DSolve can be useful theoretically or numerically but I would say mostly theoretically although I could be wrong.

  • Theoretically: An analysis of the implicit solution can provide crucial insights about a function. It can provide the domain in which it is defined, bounds, singularities and asymptotic behavior. Moreover, an implicit definition involving integrals might have interesting change of variables and integrations by parts that might highlight details about the function. Finally, an implicit solution gives a more natural way to extend the function to the complex plane to study the types and numbers of singularities around the real line (which affects matters such as how easy it is to numerically integrate such a function in a given interval)

  • Numerically: It provides an alternative means to solve the equation, that is, the possibility to consider also FindRoot if NDSolve gave issues for the problem at hand. FindRoot could be faster if one only wants the endpoint of the integration and one has a good guess for this point either by looking at the graph or by prior analytical computations. If an entire interval is needed I would imagine that NDSolve would be faster unless there is an intermediate singularity in the way.

Consider then the example given.

First notice that the $\log(K[1])$ in the integral on the left hand side with the upper bound $\frac{y(x)}{x}$ and the $\log(x)$ on the right hand side shows us that this definition only applies to $x>0$ and $y(x)>0$. Hence, we will restrict the following discussion to this domain.

To get the function that defined the implicit equation one can do:

sol = DSolve[{y'[x] == 2*Log[y[x]/x], y[4] == 7}, y[x], x][[1]]

aux[y_, x_] = sol[[1]] - sol[[2]] /. y[x] -> y /. Integrate -> NIntegrate 

f[y_?NumericQ, x_?NumericQ] := aux[y, x] // Activate;

Graphs

The implicit equation is then defined by f[y,x]=0. And one can find the curve y[x] by looking for the contour where f[y,x]=0 using ContourPlot.

ContourPlot[f[y, x], {x, 0, 20}, {y, 0, 12}, PlotLegends -> Automatic]

contour_plot

The self added 0 in the image annotation is visible when hovering over the curve in Mathematica. That curve represents the y[x] that one seeks.

Theoretical part: analysis of the implicit equation using insights from the graph

Notice that this curve is bounded in the upper left plane and y[x] goes to 0 both for x=0 and for some special x. To find that x analytically one can consider the behavior of the integral when the upper-bound goes to zero as the upper bound is $\frac{y(x)}{x}$. The behavior of the integral in special regions can be found sometimes with AsymptoticIntegrate. However, after waiting some time I did not receive an answer from Mathematica using AsymptoticIntegrate.

Instead we can use the implicit equation to find the coordinates of the maximum.

At the maximum, one has $y'(x_0)=0$. Using that within the original differential equation, we may deduce from $\log(\frac{y(x_0)}{x_0})=0$ that $y(x_0)=x_0$. Now the implicit equation part, one may use that in the implicit equation to obtain $\log(x_0)$ as a combination of integrals thereby allowing us to find an analytical formula for $x_0$ and $y(x_0)$. Not that much but in another example one could get nice asymptotics.

Numerical Part

As mentioned above one can find y[x] using NSolve with the implicit equation. I do not see any benefit of doing that in this case but for the sake of comparison with NDSolve I will.

Initialization:

yroot[1] = 0; iterations = 40;
xstart = 0.5; xend = 18.5;
xlist = Subdivide[xstart, xend, iterations];

follow the solution by continuity updating the guess with prior solutions:

Do[yroot[i + 1] = y /. FindRoot[f[y, xlist[[i + 1]]] == 0,
{y, yroot[i]}], {i, iterations}]

The graph:

Transpose[{xlist, yroot /@ Range[iterations + 1]}] // ListPlot

points

Comparison with NDSolve

Plot[Evaluate@NDSolveValue[{y'[x] == 2*Log[y[x]/x], y[4] == 7}, y[x], {x, 0, 18.5}], {x, 0, 18.5}]

nd

Summary

In this case it is hard to find a theoretical or numerical benefit to the implicit solution provided but in general an implicit solution can be an opportunity to obtain more precise statements than the visual look of a graph.

$\endgroup$
1
  • $\begingroup$ Thank you for the summary + 1, informative. $\endgroup$
    – Moo
    Commented Oct 20, 2022 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.