I would like to calculate a sweep-up for the Duffing equation. To be more precise, I'm looking for a solution to the ode
$\qquad x''(t)+0.1x'(t)+x(t) +0.01 x^3(t) = 0.8 \cos(\eta t) $
Let's say for the initial conditions $x(0)=x'(0)=0$ and $\eta \in [0.8, 1.2]$ with increment size $0.001$ and $t \in [0,2\cdot 100 \frac{\pi}{\eta}]$. But instead of using the same initial conditions for every $\eta$, I would like to choose new initial conditions $x_{j+1}(0)=x_j(2\cdot 100 \frac{\pi}{\eta})$ and $x_{j+1}'(0)=x_j'(2\cdot 100 \frac{\pi}{\eta})$ every time $\eta$ increases, where $x_j$ is the solution of the previous computation with the previous $\eta$. As output I would like to have the maximum value of $x$ for every $\eta$ neglecting the transients.
I tried it using Table, which yields reasonable results but takes some time to calculate. Here is the code
numbper = 100; (*number of periods*)
sol = ParametricNDSolveValue[{x''[t] + 1/10 x'[t] + x[t] + 1/100 x[t]^3 ==
8/10 Cos[η t], x[0] == x0, x'[0] == v0}, {x, x'}, {t, 0, numbper*2 Pi/η},
{x0, v0, η}];
xstart = sol[0, 0, 0.79][[1]][numbper*2 Pi/0.79];
vstart = sol[0, 0, 0.79][[2]][numbper*2 Pi/0.79];
dη = 0.001;
sweepup = Table[{
NMaxValue[{sol[xstart, vstart, η][[1]][
t], (numbper - 1)*2 Pi/η <= t <= numbper*2 Pi/η},
t], xstart =
sol[xstart, vstart, η][[1]][(numbper - 1)*2 Pi/η];
vstart = sol[xstart, vstart, η][[2]][numbper*2 Pi/η];}
, {η, 0.8, 1.2, dη}];
I'm now wondering what I could do to speed things up.
Doinstead ofFor. Write it down as it comes to your mind and optimize later. – Henrik Schumacher Jan 11 '18 at 17:54