I am having trouble trying to plot solution curves onto a vector field for this certain ODE. I have tried plotting with multiple different initial conditions/ different constants however I keep getting a blank graph.

eq1 = y'[x] == E^(-y[x])*Cos[y[x]];

sol1b = DSolve[eq1, y[x], x] /. C[1] -> c

   {{y[x] -> 
   InverseFunction[(1 - I) E^((1 + I) #1)
        Hypergeometric2F1[1/2 - I/2, 1, 3/2 - I/2, -E^(2 I #1)] &][
    c + x]}}

vf1 = VectorPlot[{1, E^(-y)*Cos[y]}, {x, -10, 10}, {y, -10, 10},
   VectorScale -> {Large, 1/2, Automatic}];

p2b = Plot[
  Evaluate[Table[y[x] /. sol1b, {c, 0, 10, 1}]], {x, -10, 10}, 
  PlotRange -> All]

Show[vf1, p2b]

This was my latest attempt. The vector field comes out great, it is my p2b plot that is causing problems. I'm guessing this has something to do with InverseFunction, but I really have no idea. I have tried lots of tricks from other posts but nothing seems to be working. Any suggestions ?


1 Answer 1


Would you want something like this?

vf1 = VectorPlot[{1, E^(-y)*Cos[y]}, {x, -10, 10}, {y, -10, 10}, 
  VectorScale -> {Large, 1/2, Automatic}, StreamPoints -> Coarse, 
  StreamStyle -> {Red, Thick}]

Mathematica graphics

(Internally, NDSolve is used to numerically compute the solution curves, a.k.a. stream lines. This avoids the apparent branch-switching problems of the symbolic solution.)

  • $\begingroup$ Great answer (+1), from which I learned a lot. However, it seems to me that VectorPlot has swept problems under the rug, so to speak. Notice, for instance, the discontinuities at y -> -1.5708 and near -5 and -8. Incidentally, the core error in my answer was that I assumed c to be real. $\endgroup$
    – bbgodfrey
    Oct 6, 2015 at 18:40
  • $\begingroup$ @bbgodfrey Thanks. Yes, both VectorPlot and StreamPlot deal with equilibria by leaving white space. You kinda have to get used to it, I guess. $\endgroup$
    – Michael E2
    Oct 6, 2015 at 23:43
  • $\begingroup$ @MichaelE2 Thank you! This is a very helpful work-around that I never knew about. $\endgroup$
    – sdalke
    Oct 7, 2015 at 19:29

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.