I need to solve and plot the slope field for the equation y'=cos(y)-1.
DSolve[{y'[x] == -1 + Cos[y[x]]}, y[x], x]
VectorPlot[{1, (-1 + Cos (y))}, {x, -3, 3}, {y, -3, 3}]
I get an empty graph. Any help?
As suggested in the comment, you are suppose to use Cos[]
not Cos()
in Mathematica.
You can solve the ode and combine the VectorPlot
with the solution curves like this
soln[y0_?NumericQ] :=First@DSolve[{y'[x] == -1 + Cos[y[x]], y[0] == y0}, {y}, {x, 0,10}];
vp = VectorPlot[{1, (-1 + Cos[y])}, {x, -3, 3}, {y, -3, 3}];
Show[vp, Plot[
Evaluate[{y[x]} /. soln[#] & /@ Range[-20, 20, 0.3]], {x, -3, 3},
PlotRange -> All, MaxRecursion -> 8, AxesLabel -> {"x", "y"}]]