# How to plot the basin of attraction of a forced Duffing equation using Mathematica? [duplicate]

I have tried to plot the basin of attraction of the system \begin{eqnarray} &&\frac{dx}{dt}={y},\\[3mm] &&\frac{dy}{dt}=0.01\cos(0.54t)-1.875x^3-0.02y. \end{eqnarray} Is there anybody who can help me with this problem?

## marked as duplicate by corey979, C. E., zhk, xzczd, bbgodfreyMar 16 '17 at 20:46

BTW, Almost exactly, the same question has been answered very elegantly by @xzczd.

Here is a starting point for you.

sol[x0_?NumericQ, y0_?NumericQ] := First@NDSolve[{x'[t] == y[t],
y'[t] == 0.01*Cos[0.54*t] - 1.875*x[t]^3 - 0.02*y[t], x[0] == x0,
y[0] == y0}, {x, y}, {t, 0, 10}];

ParametricPlot[ Evaluate[{x[t], y[t]} /. sol[#, #] & /@ Range[-1, 1, 0.1]], {t, 0,
10}, PlotRange -> All, PlotPoints -> 500, MaxRecursion -> 5, AxesLabel -> {"x", "y"}]


This is a problem custom-made for ParametricNDSolveValue, which allows us to simplify @Maple SE's fine answer further.

ClearAll[duffing, solve, x, y, t];

duffing =
{x'[t] == y[t],
y'[t] == 0.01*Cos[0.54*t] - 1.875 x[t]^3 - 0.02*y[t]};

solve = ParametricNDSolveValue[{duffing, x[0] == x0, y[0] == y0},
{x[t], y[t]}, {t, 0, 10}, {x0, y0}];

ParametricPlot[
solve[#, #] & /@ Range[-1, 1, 0.1] // Evaluate, {t, 0, 10},
AxesLabel -> {HoldForm[x[t]], HoldForm[y[t]]}]