This first order ode \begin{align*} y'&= \frac{\cos(y)}{x}\\ y(1)&=\pi \end{align*} By existence and uniqueness theorem has solution and the solution is unique (on interval that include the initial point.

We see that $y'=\frac{\cos(y)}{x}=f(x,y)$. We see that $f$ is defined for all $y$ and all $x$ except $x=0$, and $f_y$ is also defined for all $y$ and all $x$ except $x=0$. Since initial conditions is not at $x=0$, then theory say that solution exists and is unique on some interval that includes the point $(1,\pi)$. So Mathematica should be able to find it.

But DSolve does not give a solution at all. Could someone come with a workaround?

DSolve[{y'[x] == Cos[y[x]]/x, y[1] == Pi}, y[x], x]

Mathematica graphics

Here is the solution curve using Stream plot passing through IC


Mathematica graphics

Here is the solution using NDSolve


Mathematica graphics

Any one knows why Mathematica does not solve this?

Btw, the analytical solution given by Maple is

ode:=diff(y(x), x) = cos(y(x))/x;

\begin{align*} y = \arctan \left(\frac{x^{2}-1}{x^{2}+1}, -\frac{2 x}{x^{2}+1}\right) \end{align*}

Using the normal definition of $\arctan(y,x)$ and not Mathematica's defintion of $\arctan(x,y)$ However, when I Plot Maple's solution it is not continuous at $x=1$. So may be Maple's solution also has problem:

 plot(arctan((x^2 - 1)/(x^2 + 1), -2*x/(x^2 + 1)),x=0..3)

enter image description here

V 13.3.1 on windows 10


3 Answers 3


The inverse problem is solved without problems

solx = DSolve[{x[y] == Cos[y ] x'[y], x[Pi] == 1}, x, y ][[1]]
(*{x -> Function[{y}, -E^(2 ArcTanh[Tan[y/2]])]}*)

ParametricPlot[{x[y], y} /. solx, {y, -3, 3},PlotRange -> {{0, Pi}, {-Pi, Pi}}, AspectRatio -> 1/2]

enter image description here

  • 1
    $\begingroup$ How do you explain the discontinuity in the plot? $\endgroup$
    – user64494
    Dec 21, 2023 at 18:10
  • 1
    $\begingroup$ ode is singular for y->Pi/2 . In other words Limit[y[x],Abs[x->Infinity]==Pi/2 $\endgroup$ Dec 21, 2023 at 18:19
  • $\begingroup$ The horizontal asymptote is also plotted as a point at infinity outside the given domain. right? $\endgroup$
    – Narasimham
    Dec 22, 2023 at 0:15
  • 1
    $\begingroup$ What about the discontinuity at $x=1$, which is at the initial condition $x=1$, $y=\pi$ where the ODE is not singular? The inverse problem seems to have a problem. $\endgroup$
    – Goofy
    Dec 22, 2023 at 0:38
  • 1
    $\begingroup$ Again: Point {1, Pi} is not included in the solution solx above. I thought this was clear. I agree that {1, Pi} is included in the true mathematical solution, but x[Pi] /. solx evaluates to Indeterminate, not 1. I am beginning to think you mean something else by "Point {1,Pi} is included": for instance, that x[Pi] /. solx evaluates to a numeric value for you. (I'm using V13.3, in case it's a version issue. But I doubt it is, since Tan[y/2] is undefined at y = Pi.) $\endgroup$
    – Goofy
    Dec 24, 2023 at 2:59

By hand separable method, after substitution $u = \sin(y/2)$:

Integrate[2/((1 - 2 u[x]^2) Sqrt[1 - u[x]^2]), {u[x], 1, Sin[Y/2]}, 
  Assumptions -> {1/2 < Y < 3/2}] == 
 Integrate[1/x, {x, 1, X}, Assumptions -> {0 < X}]

(* 2 ArcCoth[Tan[Y/2]] == Log[X] *)

ContourPlot[2 ArcCoth[Tan[Y/2]] == Log[X],
 {X, $MachineEpsilon, 2}, {Y, Pi/2, 3 Pi/2}]

enter image description here

I don't seem to be able to solve for Y without incurring branch-cut problems. Could sort them out by hand, of course.

After some playing around I get this form, which avoids branch cut issues:

Y == 2 ArcTan[-1 + X, 1 + X]

{y'[x] == Cos[y[x]]/x, y[1] == Pi} /. 
  y -> Function[x, 2 ArcTan[-1 + x, 1 + x]] // FullSimplify

(* {True, True} *)

Okay, here's a workaround, based in ideas springing from the foregoing solution.

 ArcTan[Tanh[e_]] := ArcTan[Cosh[e], Sinh[e]];
 dsol = First@DSolve[{y'[x] == Cos[y[x]]/x, y[1] == Pi}, y[x], x] // 
Plot[y[x] /. dsol, {x, 0, 2}]

(* {y[x] -> 2 ArcTan[I Sinh[Log[x]/2], I Cosh[Log[x]/2]]} *)

enter image description here

You can use ArcTan[Tanh[e_]] := ArcTan[Cosh[e]/I, Sinh[e]/I] to get rid of the extraneous pair of Is.

Remark on the difficulty: It seems most solutions that can be coaxed out of DSolve have something evaluates to infinity at the initial condition when determining the constant of integration. In each case, the entire expression being evaluated has a limit (has the form $\infty/\infty$), but the limit is not used by the solver. And the process fails.

  • $\begingroup$ I get Y == 2 ArcTan[-1 + X, 1 + X] fooling around with the solution above. $\endgroup$
    – Goofy
    Dec 21, 2023 at 18:49
  • $\begingroup$ How do you switch from y[x] to u[x]? How about the initial condition y[1]==Pi? $\endgroup$
    – user64494
    Dec 21, 2023 at 19:22
  • $\begingroup$ @user64494 Sorry, I forgot to mention the substitution. (Mma does it {y'[x] == Cos[y[x]]/x, y[1] == Pi} /. y -> Function[t, 2 ArcSin[u[t]]] // TrigExpand // Simplify. For a separable IVP $dy/v(y) = dx/w(x), y(x_0) =y_0$, the solution is $\displaystyle\int_{y_0}^y {dy \over v(y)} = \int_{x_0}^x {dx \over w(x)}$. After the substitution, the IC becomes $u(1) = 1$. $\endgroup$
    – Goofy
    Dec 22, 2023 at 0:28

$$ \frac {dy}{dx}= \frac{\cos y }{x}$$

$$ \int \sec y ~dy =\int\frac {dx}{x}$$

Integrate, include arbitrary constant

$$ \log( \tan (\pi/4+ y/2)) = \log ( C x)$$

$$ y= 2\tan ^{-1} ( Cx) - \pi/2 ;$$

Variable separable ode, solved directly.

The inverse tan function solution has a horizontal asymptote for large enough $x.$

I expected Mathematica should solve it by DSolve, with Reduce without numerical NDSolve, but sorry, the above does not answer your question; I was also troubled by inverse trig functions not working with Reduce.


To avoid an inverse function solution we can can find inverse function ode itself as $$ \frac{-1}{y'(x)} = \frac{\cos x }{y} $$

$$\text{ having solution } Cy= \tan (\pi/4+x/2) \text{ that should go through point } (1,\pi/2).$$

Then Mathematica may DSolve straight. The $(x,y)$ need to be swapped back.


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.