1 Introduction

The optimization of time-delay systems has been the subject of intensive research for many years. Such systems arise naturally in control applications where unmodeled actuator dynamics results in delays between input signals and actuator responses [19], car following models that account for driver reaction times [15], and machine tool dynamics due to the regenerative effect [20]. The wide range of applications has motivated the development of novel techniques for their optimization. For example, Göllmann et al. [4] used a formulation based on the Pontryagin minimum principle to derive necessary optimality conditions for optimal control problems with delays in state and control variables. The obtained equations were discretized and transformed into a large-scale nonlinear programming model, which was then solved using off-the-shelf solvers. In another investigation, Yusoff and Sims [22] combined the semi-discretization method [10] for time-periodic delay equations with differential evolution to optimize a variable helix/pitch tool geometry for regenerative chatter mitigation. Their results were also validated experimentally, confirming the predicted significant improvements in chatter stability. This problem of optimal selection of parameters for subtractive manufacturing was also reported in [8, 9, 21]. Liao et al. [13] developed an optimization technique for periodic solutions of delay-differential equations using the harmonic balance method and continuation techniques. They posed an amplitude optimization problem subject to the algebraic constraints obtained by substitution of a truncated Fourier representation in the governing equation along with the stability conditions. The sensitivity expressions were analytically derived, and the optimization problem was then solved for the unknown Fourier coefficients and the unknown parameters. The delayed Duffing oscillator was used to validate the methodology.

The calculus of variations serves as a useful tool for constrained optimization problems. Here, a Lagrangian functional is constructed by combining the objective function with the imposed constraints using Lagrange multipliers (adjoint variables) as coefficients. The vanishing of the variations of the Lagrangian with respect to the design variables and the Lagrange multipliers then yields the necessary optimality conditions for a stationary point. In general, these equations cannot be solved directly. Instead, nonlinear solvers may be applied to various finite-dimensional discretizations. A major challenge with this approach is the selection of a good initial guess which converges to the desired solution. A resolution built on principles of parameter continuation was originally proposed in the work of Kernévez and Doedel [11]. There, a sequence of properly initialized stages of continuation along one-dimensional manifolds of solutions to a subset of the necessary optimality conditions was used to connect the local extremum to an initial solution guess with vanishing Lagrange multipliers. This methodology was recently revisited by Li and Dankowicz [12] and there cast in terms of partial Lagrangians relevant to the general context of constrained optimization of integro-differential boundary-value problems without delay. Importantly, this work showed how the Lagrangian structure was consistent with a staged construction paradigm implemented in the software package coco.

In this work, we generalize the successive continuation approach of Kernévez and Doedel to optimization along families of periodic and quasiperiodic orbits in dynamical systems with delay. We derive the necessary optimality conditions from a suitably constructed Lagrangian without first discretizing the governing equations and unknowns. This approach is in contrast to other studies [16], in which the discretization of the governing equations is first carried out, and then, the Lagrangian is constructed based on the discretized equations. In our formulation, the Lagrange multipliers satisfy coupled, piecewise-defined, boundary-value problems with both delayed and advanced arguments. Depending on the imposed constraints, the Lagrange multipliers may be discontinuous or nonsmooth at the interval boundary points, naturally resulting in a multi-segment problem [1].

We first motivate our interest and approach with the problem of optimization of the response amplitude of a harmonically forced, scalar, linear, delay-differential equation in Sect. 2. The general framework for problems with single delays is then considered in Sect. 3, first for periodic orbits and subsequently for families of two-dimensional quasiperiodic invariant tori. As discussed in detail, the latter optimization problem falls into the category of constrained optimization for partial differential equations (PDEs) [5, 6, 14], for which the necessary optimality conditions take the form of coupled, piecewise-defined PDEs with non-local coupling, as well as associated boundary and interval conditions representing periodicity in one dimension and rotation in the other. Subsections of Section 3 consider example applications to the search for a saddle of the response amplitude of a harmonically forced Duffing oscillator subject to delayed feedback control and a geometric fold along a family of quasiperiodic trajectories for constant rotation number. Analysis using the coco software package validates the successive continuation approach, as well as the simultaneous discretization of the dynamic constraints and adjoint equations. A number of additional considerations and opportunities for future work are considered in the concluding section.

2 Motivating example

We illustrate the general framework for optimization along families of solutions to delay-differential equations (DDEs) by first considering periodic responses z(t) of frequency \(\omega \) for a harmonically forced, scalar, linear, delay-differential equation

$$\begin{aligned} \dot{z}=-z- z\left( t-1\right) + \text {cos}\omega t , \end{aligned}$$
(1)

where we omit (here, and throughout the paper) functional arguments when they are obvious from the context. It follows from the method of undetermined coefficients that such responses are of the harmonic form

$$\begin{aligned} z(t)=r(\omega )\cos (\omega t-\theta (\omega )), \end{aligned}$$
(2)

where

$$\begin{aligned} r(\omega )=\left[ 2+\omega ^2-2 \omega \sin \omega +2 \cos \omega \right] ^{-1/2} \end{aligned}$$
(3)

and

$$\begin{aligned} \cos \theta (\omega )=-\frac{1+\cos \omega }{r^3(\omega )},\, \sin \theta (\omega )=\frac{\sin \omega -\omega }{r^3(\omega )}. \end{aligned}$$
(4)

Let us consider the optimization problem of finding the forcing frequency \(\omega \) for which such a periodic response has maximum amplitude. It follows from (3) that the maximum amplitude \(r_\mathrm {crit}\doteq r(\omega _\mathrm {crit})\approx 0.89\) is achieved for \(\omega _{\mathrm {crit}}\approx 1.72\) (cf. Fig. 1), and that \(z(t_\mathrm {crit})=r_\mathrm {crit}\) at time \(t_{\mathrm {crit}}\doteq \theta (\omega _\mathrm {crit})/\omega _\mathrm {crit}\approx 2.24\) (up to multiples of the period \(T_\mathrm {crit}\doteq 2\pi /\omega _\mathrm {crit}\approx 3.65\)). Hence, for this simple optimization problem all components of the solution are known exactly, enabling a comparison with the results of numerical algorithms.

Fig. 1
figure 1

Frequency response diagram for the steady-state periodic solutions of the harmonically forced, scalar, linear delay-differential equation (1). The maximum value of the amplitude is \(r_\mathrm {crit}\approx 0.8911\) which occurs for \(\omega =\omega _\mathrm {crit}\approx 1.7207\) (\(T=T_\mathrm {crit}\approx 3.6516\))

2.1 Formulation as a constrained optimization problem

We transform the above optimization problem into a format suitable for a general numerical solver by introducing the excitation period \(T=2\pi /\omega \) as an unknown (T replaces \(\omega \)) and rescaling time (calling the new time \(\tau \)) such that \(x(\tau )\doteq z(T\tau +T\phi /2\pi )\). Here, the free phase \(\phi \) is to be chosen so as to shift the time on the interval [0, 1] when the periodic solution x has a critical point to \(\tau =0\). Thus, we are seeking a solution to the constrained optimization problem

$$\begin{aligned} \text{ maximize }\quad \mu _A=x(0) \end{aligned}$$
(5)

with respect to a continuous function x on [0, 1], as well as the variables T and \(\phi \), subject to the equality constraints

$$\begin{aligned} x'&=-Tx-Tx\left( \tau +1-1/T\right) +T\cos \left( 2 \pi \tau +\phi \right) \nonumber \\&\quad \text{ for } \tau \in (0,1/T), \end{aligned}$$
(6)
$$\begin{aligned} x'&=-Tx-Tx\left( \tau -1/T\right) +T\cos \left( 2 \pi \tau +\phi \right) \nonumber \\&\quad \text{ for } \tau \in (1/T,1), \end{aligned}$$
(7)
$$\begin{aligned} 0&=x\left( 0\right) -x\left( 1\right) , \end{aligned}$$
(8)
$$\begin{aligned} 0&=x\left( 0\right) +x\left( 1-1/T\right) -\cos \phi . \end{aligned}$$
(9)

Here, constraints (6) and (7) impose the original delay-differential equation on the interval (0, 1). They rely on periodicity to wrap the delayed argument back into this interval assuming that \(T>1\). Constraints (8) and (9) are boundary conditions. Constraint (8) imposes periodicity also on the interval boundary, while (9) is a phase condition that ensures that \(x'(0)=0\), consistent with x having a critical point at \(\tau =0\) and justifying the maximization of x(0) as a substitute for the amplitude. By continuity of x on [0, 1] and (8), it follows that x is, in fact, a smooth function on [0, 1]. Indeed, from the explicit solution in the previous section, it follows that \(x(\tau )=r(2\pi /T)\cos 2\pi \tau \) and \(\phi =\theta (2\pi /T)\) and, in particular, that optimality is obtained for \(x(\tau )=x_\mathrm {crit}(\tau )\doteq r_\mathrm {crit}\cos 2\pi \tau \) and \(\phi =\phi _\mathrm {crit}\doteq \theta (2\pi /T_\mathrm {crit})\) for \(T=T_\mathrm {crit}\).

The constrained optimization problem (5)–(9) gives rise to the Lagrangian

$$\begin{aligned}&L\left( x(\cdot ),\phi ,T, \mu _A, \lambda _1(\cdot ),\lambda _2,\lambda _3,\eta _A\right) \nonumber \\&\quad =\mu _A+ \eta _A\left( x\left( 0\right) -\mu _A\right) \nonumber \\&\quad +\int \limits _{0}^{1/T}\lambda _{1}\left[ x^{\prime }+T\left[ x+x\left( \tau +1-1/T\right) \right. \right. \nonumber \\&\quad \left. \left. -\cos \left( 2\pi \tau +\phi \right) \right] \right] \,\mathrm {d}\tau \nonumber \\&\quad +\int \limits _{1/T}^{1-2/T}\lambda _{1}\left[ x^{\prime }+T\left[ x+x\left( \tau -1/T\right) \right. \right. \nonumber \\&\quad \left. \left. -\cos \left( 2\pi \tau +\phi \right) \right] \right] \,\mathrm {d}\tau \nonumber \\&\quad +\int \limits _{1-2/T}^{1-1/T}\lambda _{1}\left[ x^{\prime }+T\left[ x+x\left( \tau -1/T\right) \right. \right. \nonumber \\&\quad \left. \left. -\cos \left( 2\pi \tau +\phi \right) \right] \right] \,\mathrm {d}\tau \nonumber \\&\quad +\int \limits _{1-1/T}^{1}\lambda _{1}\left[ x^{\prime }+T\left[ x+x\left( \tau -1/T\right) \right. \right. \nonumber \\&\quad \left. \left. -\cos \left( 2\pi \tau +\phi \right) \right] \right] \,\mathrm {d}\tau \nonumber \\&\quad +\lambda _{2}\left( x\left( 0\right) -x\left( 1\right) \right) \nonumber \\&\quad +\lambda _{3}\left( x\left( 0\right) +x\left( 1-1/T\right) -\text {cos}\left( \phi \right) \right) , \end{aligned}$$
(10)

where the Lagrange multipliers are \(\lambda _{1}(\tau )\) (a function on [0, 1]) for the DDE constraints (6) and (7), \(\lambda _{2}\) and \(\lambda _{3}\) for the boundary conditions (8) and (9), and \(\eta _A\) for the relationship between the fitness \(\mu _A\) and x(0) in (5).

In (10), the integral for the pairing between \(\lambda _1\) and the DDE constraints has been split into 4 parts, one for each of the intervals (0,1/T), \((1/T,1-2/T)\), \((1-2/T,1-1/T)\), and \((1-1/T,1)\), reflecting different functional forms of the differential equations (6) and (7) for x on (0,1/T) and (1/T,1), respectively, and anticipating possible discontinuities in \(\lambda _1\) and \(\lambda _1'\). For example, the split at \(\tau =1-1/T\) is in anticipation of a potential discontinuity of the Lagrange multiplier \(\lambda _1\) at this instant caused by the imposition of a constraint on x evaluated at this time in (9). This discontinuity implies a potential discontinuity of \(\lambda _1'\) at \(\tau =1-2/T\). For the same reason, the appearances of x(0) in (5) and (9) suggest that \(\lambda _1(0)\ne \lambda _1(1)\) resulting in a potential discontinuity of \(\lambda _1'\) at \(\tau =1-1/T\). All functions are assumed to be continuously differentiable on the partition implied by the integrals in (10). The ordering of the discontinuity points assumes that \(T>3\) (Fig. 1 shows that the optimal T is in this range).

Imposing vanishing variations of the Lagrangian L with respect to variations in all its arguments recovers the original constraints (5)–(9) and the following adjoint system determining the Lagrange multipliers. Specifically, vanishing variations with respect to x imply

$$\begin{aligned} -\lambda _{1}^{\prime }+T\lambda _{1}+T\lambda _{1}\left( \tau +1/T\right) =0 \end{aligned}$$
(11)

for \(\tau \in \left( 0,1/T\right) \cup \left( 1/T,1-2/T\right) \cup \left( 1-2/T,1-1/T\right) \) and

$$\begin{aligned} -\lambda _{1}^{\prime }+T\lambda _{1}+T\lambda _{1}\left( \tau -1+1/T\right) =0 \end{aligned}$$
(12)

for \(\tau \in \left( 1-1/T,1\right) \). Boundary and interface conditions for these equations are obtained by considering variations with respect to x(0), x(1 / T), \(x(1-2/T)\), \(x(1-1/T)\), and x(1), corresponding in that order to

$$\begin{aligned} 0&=-\lambda _{1}(0)+\lambda _{2}+\lambda _{3}+\eta _A, \end{aligned}$$
(13)
$$\begin{aligned} 0&=\lambda _{1}(1/T)_--\lambda _{1}(1/T)_+, \end{aligned}$$
(14)
$$\begin{aligned} 0&=\lambda _{1}(1-2/T)_--\lambda _{1}(1-2/T)_+, \end{aligned}$$
(15)
$$\begin{aligned} 0&=\lambda _{1}(1-1/T)_{-}-\lambda _{1}(1-1/T)_++\lambda _{3}, \end{aligned}$$
(16)
$$\begin{aligned} 0&=\lambda _{1}(1)-\lambda _{2}, \end{aligned}$$
(17)

using the convention that \(\lambda _1(\tau ^*)_\pm \doteq \lim _{{\tau \rightarrow \tau ^*}\pm }\lambda _1(\tau )\) and recalling that \(x(\tau )\) is continuous on [0, 1]. Vanishing variations with respect to \(\phi \) and T imply the integral constraints

$$\begin{aligned} 0=\int \limits _{0}^{1}T\lambda _{1}\sin \left( 2\pi \tau +\phi \right) \,\mathrm {d}\tau +\lambda _{3}\sin \left( \phi \right) \end{aligned}$$
(18)

and

$$\begin{aligned} 0&=\int \limits _0^{1/T}\lambda _1\left( x(\tau +1-1/T)+x'(\tau +1-1/T)/T\right) \,\mathrm {d}\tau \nonumber \\&\quad +\int \limits _{1/T}^1\lambda _1\left( x(\tau -1/T)+x'(\tau -1/T)/T\right) \,\mathrm {d}\tau \nonumber \\&\quad +\int \limits _0^1\lambda _1\left( x-\cos (2\pi \tau +\phi )\right) \,\mathrm {d}\tau \nonumber \\&\quad +\lambda _3T^{-2}x'(1-1/T), \end{aligned}$$
(19)

respectively. Finally, vanishing variation with respect to \(\mu _A\) implies that

$$\begin{aligned} 1-\eta _A=0. \end{aligned}$$
(20)

In summary, the system of original constraints (5)–(9) and adjoint equations (11)–(20) is a nonlinear integro-differential boundary-value problem (BVP) defining the critical points of the Lagrangian L and the constrained optimization problem (5)–(9).

In this example, the dimension of the manifold on which the constrained optimization problem is posed equals 1, corresponding to the numbers of degrees of freedom of the nonlinear subsystem (5)–(9) (with variables x, T and \(\phi \)). In contrast, the full system (5)–(9), (11)–(20) has no such degrees of freedom and, consequently, generically has only isolated solutions. Several properties put it beyond the reach of “off-the-shelf” BVP solvers:

  1. 1.

    It consists of differential equations on multiple intervals (thus, the problem is called a multi-segment BVP) with differential functional forms and continuous “right-hand sides.” The number and length of these intervals is strongly problem dependent and may even change during the optimization process.

  2. 2.

    The differential equations evaluate their right-hand sides at times deviating from \(\tau \) (delayed or advanced arguments).

  3. 3.

    The second point leads to non-local coupling across segments that is not restricted to coupling at the boundaries of the intervals. For example, (11) couples the values of \(\lambda _1\) in \((1-2/T,1-1/T)\) to values of \(\lambda _1\) in \((1-1/T,1)\).

On the other hand, system (5)–(9), (11)–(20) has some additional structure that aids both in its construction and solution:

  1. 1.

    The equations are only forward coupled in that a solution to the original constraints (5)–(9) can be obtained independently of the values of the Lagrange multipliers, while a solution to the adjoint equations (11)–(20) requires knowledge of x, T, and \(\phi \), and generically exists, at best, only for isolated choices of x, T, and \(\phi \).

  2. 2.

    The adjoint equations (11)–(19) (thus excluding (20)) are linear and homogeneous in the Lagrange multipliers \(\lambda _j\) (\(j=1,2,3\)) and \(\eta _A\). A trivial solution of this subset of the adjoint system is therefore given by vanishing Lagrange multipliers for any x, T, and \(\phi \).

  3. 3.

    The adjoint equation (20) is trivial in both construction and solution. Imposing its solution (\(\eta _A=1\)) on the remaining adjoint system, however, renders the latter nonhomogeneous.

This structure will also be present for more general cases than the example and can be exploited in the search for solutions, as well as to generate the adjoint equations (11)–(19) automatically during a staged construction of the optimization problem similar to [12].

In this example, a few facts about the Lagrange multipliers may be deduced directly from the adjoint equations. It follows immediately from (14) and (15) that \(\lambda _1\) is continuous at \(\tau =1/T\) and \(\tau =1-2/T\), and from (11) that \(\lambda _1'\) is continuous at \(\tau =1/T\). Moreover, using the explicitly known solution for x, it follows that the Lagrange multiplier \(\lambda _3\) must equal 0 at a local extremum. Indeed, substitution of the modified phase condition

$$\begin{aligned} \delta =x\left( 0\right) +x\left( 1-1/T\right) -\cos \phi \end{aligned}$$
(21)

in lieu of (9) implies that

$$\begin{aligned} \mu _A=\left( \cos \phi +\cos (\omega +\phi )+\omega \sin \phi \right) /r(\omega ), \end{aligned}$$
(22)

where \(\phi \) is implicitly determined by

$$\begin{aligned} \delta =\omega \left( \sin \phi +\sin (\omega +\phi )-\omega \cos \phi \right) /r(\omega ) \end{aligned}$$
(23)

for \(\delta \approx 0\). Implicit differentiation of both conditions with respect to the residual \(\delta \) shows that the rate of change of \(\mu _A\) with respect to \(\delta \) equals 0 at \(\delta =0\). This, in turn, implies that \(\lambda _3=0\) at an extremum, i.e., that \(\lambda _1\) is, in fact, continuous also at \(\tau =1-1/T\) and, consequently, continuously differentiable also at \(\tau =1-2/T\). In contrast, \(\lambda '_1\) experiences a discontinuity at \(\tau =1-1/T\) for nonzero \(\eta _A=\lambda _1(0)-\lambda _1(1)\).

2.2 Simple continuation

According to the properties enumerated above, a solution to (5)–(9), (11)–(20) may be sought using a method of successive continuation [11, 12] with an embedded multi-segment boundary-value problem implementation that permits evaluation of the right-hand side at arguments shifted by arbitrary times. Specifically, this method overcomes the problem of initializing a nonlinear solver for the full system by defining a sequence of continuation problems with one-dimensional solution manifolds that connect an initial solution guess with Lagrange multipliers all equal to 0 with the sought critical point for which \(\eta _A\) must equal 1.

To this end, we consider the system given by the relationship between \(\mu _A\) and x(0) in (5), the boundary-value problem constraints (6)–(9), and the adjoint integral-differential boundary-value problem (11)–(19), but purposely omit the algebraic constraint (20). Although we anticipate that \(\lambda _3\) will equal 0 throughout the analysis, we keep \(\lambda _3\) as an unknown and monitor its value during continuation. By linearity and homogeneity of the adjoint subsystem in the Lagrange multipliers \(\lambda _j\) and \(\eta _A\), it follows that solutions to the full system lie on either of two one-dimensional manifolds. The first of these consists of functions \(x(\tau )=r(2\pi /T)\cos 2\pi \tau \) with corresponding T, \(\phi \), and \(\mu _A=x(0)=r(2\pi /T)\), and with vanishing Lagrange multipliers. The second manifold consists of the periodic solution \(x_\mathrm {crit}(\tau )=r_\mathrm {crit}\cos 2\pi \tau \) with corresponding \(T=T_\mathrm {crit}\), \(\phi =\phi _\mathrm {crit}\), and \(\mu _A=r_\mathrm {crit}\), and with varying Lagrange multipliers proportional to \(\eta _A\). The two manifolds clearly intersect at the local extremum of \(\mu _A\) along the first manifold. The sought solution to the complete set of Eqs. (5)–(9), (11)–(20) corresponds to the point along the second manifold where \(\eta _A=1\).

In this example, the solutions along the first manifold are known explicitly. In other cases, an initial periodic response may be approximately obtained from the dynamically stable solution by direct simulation. Given such an initial solution guess for x, T, and \(\phi \), a nonlinear solver may be employed to converge to a point on the manifold. A numerical continuation algorithm (e.g., pseudo-arclength continuation) may then be used to generate a sequence of points along the manifold, meanwhile monitoring for local extrema of \(\mu _A\) and singular points for the system Jacobian (corresponding to branch points on the manifold). As shown above, and true also in the general case, these coincide. Using standard techniques, numerical continuation may proceed from such a branch point along the secondary manifold with the help of a candidate direction of continuation, for example, one that is (i) transversal to the tangent direction to the original solution manifold and (ii) in the plane spanned by the tangent directions to the two manifolds at the branch point.

Continuation using such an implementation in the coco software package [18] approximately locates an extremum (in the form of a fold point in \(\mu _A\) along the solution manifold) at \(T\approx 3.6515\) as shown in Fig. 2. Branch switching from the nearby branch point (exact coincidence is lost due to discretization) and continuation until \(\eta _A=1\) yields the graphs of \(x(\tau )\) and \(\lambda _1(\tau )\) shown in Fig. 3. As seen in the bottom panel, \(\lambda _1(\tau )\) is approximately continuous at \(1-1/T\approx 0.73\), albeit with discontinuous derivative at this point, since \(\lambda _1(0)-\lambda _1(1)=1\).

Fig. 2
figure 2

Results from numerical continuation with vanishing Lagrange multipliers. The maximum value of \(\mu _A\) is located at \(T\approx 3.6515\) and is here identified by the label BP, since it approximately coincides with a branch point

Fig. 3
figure 3

a\(x(\tau )\) and b\(\lambda _1(\tau )\) at the terminal point of the second stage of continuation with \(\eta _A=1\). The upper panel shows a comparison between the numerical solution and the analytical solution at the extremum. The bottom panel shows the Lagrange multiplier associated with the imposition of the DDE admitting a slope discontinuity at \(\tau =1-1/T\)

3 General optimization framework

In this section, we discuss the general methodology for optimization on periodic and quasiperiodic solutions \(z(t)\in \mathbb {R}^{n}\) of delay-differential equations with a single delay of the form

$$\begin{aligned} \dot{z}=f\left( t,z,z\left( t-\alpha \right) ,p\right) , \end{aligned}$$
(24)

where \(f:\mathbb {R}^{1}\times \mathbb {R}^{n}\times \mathbb {R}^{n}\times \mathbb {R}^{q}\rightarrow \mathbb {R}^{n}\) is periodic in its first argument with period T. Here, \(\alpha \) and p denote the time delay and the problem parameters (excluding T), respectively.

As the motivating example in the previous section illustrates, the problem Lagrangian and, by implication, the adjoint equations are linear in the Lagrange multipliers. The adjoint equations may therefore be constructed term-by-term by successively deriving the contributions of disjoint collections of constraints from the corresponding partial Lagrangians associated with a subset of the Lagrange multipliers. Until the full set of constraints has been considered, the adjoint equations are not completely known. The following subsections discuss the partial Lagrangians and the implied contributions to the adjoint equations resulting from the DDE constraints and boundary conditions associated with periodic and quasiperiodic orbits. For particular examples, we indicate the additional contributions associated with problem-specific constraints that complete the construction of the adjoint equations. In all cases, the contribution from the objective function to the Lagrangian implies the algebraic adjoint condition that the corresponding Lagrange multiplier (\(\eta _A\) in the previous section) must equal 1 at a stationary point.

3.1 Periodic orbits

Suppose first that \(T>\alpha \) and consider the problem of optimizing a scalar-valued objective functional on a family of continuous solutions \(x(\tau )\) to the differential equations

$$\begin{aligned} x^{\prime }&=Tf\left( T\tau ,x,x\left( \tau +1-\alpha /T\right) ,p\right)&\text{ for } \tau \in \left( 0,\alpha /T\right) , \end{aligned}$$
(25)
$$\begin{aligned} x^{\prime }&=Tf\left( T\tau ,x,x\left( \tau -\alpha /T\right) ,p\right)&\text{ for } \tau \in \left( \alpha /T,1\right) ,\nonumber \\ \end{aligned}$$
(26)

and the boundary conditions

$$\begin{aligned} x\left( 0\right) -x\left( 1\right) =0. \end{aligned}$$
(27)

By a rescaling of the independent variable by T, such solutions correspond to periodic solutions of (24) with period T. By continuity and periodicity, such solutions must be continuously differentiable to all orders.

Suppose, in fact, that \(T>3\alpha \) and that the objective functional and any additional constraints depend on pointwise values of \(x(\tau )\) only at \(\tau =0\), \(\tau =1\), and \(\tau =\beta \) for some \(\beta =\beta (\alpha ,T)\) such that

$$\begin{aligned} 2\alpha /T<\beta <1-\alpha /T. \end{aligned}$$
(28)

As we show below, such dependence results in an additional adjoint equation associated with variations with respect to \(x(\beta )\). Other pointwise dependencies of the objective functional would be treated similarly, while dependence on an integral over the entire interval [0, 1] of a function of x would not result in additional adjoint equations. We may formulate a corresponding partial Lagrangian

$$\begin{aligned}&L_\mathrm {BVP}\left( x(\cdot ),\alpha ,T,p,\lambda _f(\cdot ),\lambda _\mathrm {bc} \right) \nonumber \\&\quad =\lambda _{\mathrm {bc}}^\text {T}\left( x(0)-x(1)\right) +\int \limits _{0}^{\alpha /T}\lambda _{f}^\text {T}\left( x^{\prime }-Tf_{1}\right) \, \mathrm {d}\tau \nonumber \\&\qquad +\int \limits _{\alpha /T}^{\beta -\alpha /T}\lambda _{f}^\text {T} \left( x^{\prime }-Tf_{0} \right) \,\mathrm {d}\tau +\int \limits _{\beta -\alpha /T}^{\beta } \lambda _{f}^\text {T}\left( x^{\prime }-Tf_{0} \right) \,\mathrm {d}\tau \nonumber \\&\qquad +\int \limits _{\beta }^{1-\alpha /T}\lambda _{f}^\text {T}\left( x^{\prime }-Tf_{0} \right) \,\mathrm {d}\tau +\int \limits _{1-\alpha /T}^{1} \lambda _{f}^\text {T}\left( x^{\prime }-Tf_{0} \right) \,\mathrm {d}\tau , \end{aligned}$$
(29)

where \(f_{j}(\tau )=f\left( T\tau ,x\left( \tau \right) ,x \left( \tau +j-\alpha /T\right) ,p\right) \). Here, \(\lambda _{f}(\tau )\) and \(\lambda _{\mathrm {bc}}\) are the Lagrange multipliers associated with the imposition of the differential equations and boundary conditions, respectively, and each integrand is assumed to be continuously differentiable on the corresponding interval. The splitting of the integral is here motivated by an anticipated discontinuity of \(\lambda _f\) at \(\tau =\beta \) and, consequently, of \(\lambda _f'\) at \(\tau =\beta -\alpha /T\), the different functional forms of the original DDEs on the intervals \((0,\alpha /T)\) and \((\alpha /T,1)\), and an anticipated discontinuity in \(\lambda _f'\) also at \(\tau =1-\alpha /T\).

By the stated assumptions on the objective function and any additional constraints, it is easy to show that, at a stationary point of the total Lagrangian, \(\lambda _f(\tau )\) must be continuous at \(\tau =\alpha /T\), \(\tau =\beta -\alpha /T\), and \(\tau =1-\alpha /T\). Using the notation

$$\begin{aligned} f_{j,k}(\tau )&=\partial _kf(T\tau ,x(\tau ),x(\tau +j-\alpha /T),p), \end{aligned}$$
(30)
$$\begin{aligned} f_{j,q}(\tau )&=\frac{\mathrm {d}}{\mathrm {d}\, q}f\left( T\tau ,x\left( \tau \right) ,x\left( \tau +j-\alpha /T\right) ,p\right) \end{aligned}$$
(31)

for \(j=0,1\) and \(q=\alpha ,T\) (\(\partial _kf\) is the partial derivative of f with respect to its kth argument, \(\mathrm {d}/\mathrm {d}q\) is the total derivative of an expression with respect to q), the contributions to the necessary adjoint conditions for a stationary point of the total Lagrangian are given by

$$\begin{aligned}&-\lambda _{f}^{\prime \text {T}}-T\lambda _{f}^{\text {T}}f_{1,2}-T \lambda _{f}^{\text {T}}\left( \tau +\alpha /T\right) f_{0,3}\left( \tau +\alpha /T\right) \end{aligned}$$
(32)

for variations with respect to \(x(\tau )\) on \(\tau \in \left( 0,\alpha /T\right) \);

$$\begin{aligned}&-\lambda _{f}^{\prime \text {T}}-T\lambda _{f}^{\text {T}}f_{0,2}-T \lambda _{f}^{\text {T}}\left( \tau +\alpha /T\right) f_{0,3}\left( \tau +\alpha /T\right) \end{aligned}$$
(33)

for variations with respect to \(x(\tau )\) on \(\tau \in \left( \alpha /T,\beta -\alpha /T\right) \cup \left( \beta -\alpha /T,\beta \right) \cup \left( \beta ,1-\alpha /T\right) \);

$$\begin{aligned}&-\lambda _{f}^{\prime \text {T}}-T\lambda _{f}^{\text {T}}f_{0,2}-T\lambda _{f}^{\text {T}}\left( \tau +\alpha /T-1\right) \nonumber \\&\quad f_{1,3}\left( \tau +\alpha /T-1\right) \end{aligned}$$
(34)

for variations with respect to \(x(\tau )\) on \(\tau \in \left( 1-\alpha /T,1\right) \);

$$\begin{aligned}&-\lambda _{f}^\text {T}\left( 0\right) +\lambda _\mathrm {bc}^\text {T},&\lambda _{f}^\text {T}(\beta )_--\lambda _{f}^\text {T}(\beta )_+,&\lambda _{f}^\text {T}\left( 1\right) -\lambda _\mathrm {bc}^\text {T}, \end{aligned}$$
(35)

for variations with respect to x(0), \(x(\beta )\), and x(1), respectively;

$$\begin{aligned}&-\int _{0}^{\alpha /T}\lambda _{f}^{\text {T}}Tf_{1,\alpha }\,\mathrm {d} \tau -\int _{\alpha /T}^{1}\lambda _{f}^{\text {T}}Tf_{0,\alpha }\,\mathrm {d}\tau \end{aligned}$$
(36)

for variations with respect to \(\alpha \);

$$\begin{aligned}&-\int _{0}^{\alpha /T}\lambda _{f}^{\text {T}}\left( f_{1} +Tf_{1,T}\right) \, \mathrm {d} \tau \nonumber \\&-\int _{\alpha /T}^{1}\lambda _{f}^{\text {T}}\left( f_{0} +Tf_{0,T}\right) \,\mathrm {d}\tau \end{aligned}$$
(37)

for variations with respect to T; and

$$\begin{aligned}&-\int _{0}^{\alpha /T}\lambda _{1}^{\text {T}}Tf_{1,4}\,\mathrm {d}\tau -\int _{\alpha /T}^{1}\lambda _{1}^{\text {T}}Tf_{0,4}\,\mathrm {d}\tau \end{aligned}$$
(38)

for variations with respect to p. The terms \(f_{j,T}\) and \(f_{j,\alpha }\) in (36) and (37) both contain time derivatives \(x'\) with delayed or advanced arguments, since T and \(\alpha \) both appear in the evaluation of x in the third arguments of \(f_0\) and \(f_1\).

As previously anticipated, the explicit dependence of the Lagrangian on the internal state point \(x(\beta )\) results in a potential discontinuity of the Lagrange multiplier \(\lambda _{f}(\tau )\) at \(\tau =\beta \). Continuous differentiability of \(x(\tau )\) on [0, 1] and of \(\lambda _f(\tau )\) on \((0,\beta -\alpha /T)\), \((\beta -\alpha /T,\beta )\), \((\beta ,1-\alpha /T)\), and \((1-\alpha /T,1)\) implies that the necessary conditions for an extremum are in the form of a multi-segment boundary-value problem in a single trajectory segment for \(x(\tau )\) and four coupled trajectory segments for \(\lambda _f(\tau )\). A similar result is obtained, for example, in the limiting case when \(\beta =1-\alpha /T\). This case specializes to the example discussed in the previous section, since there \(\alpha =1\), \(\beta =1-1/T\), and \(T>3\). In contrast, when \(\beta \) is either 0 or 1, i.e., when there is no dependence of the objective function or any additional constraints on an internal point, then we obtain a single trajectory segment for \(x(\tau )\) and three coupled trajectory segments for \(\lambda _f(\tau )\) with both variables continuous throughout the interval [0, 1].

3.2 A Duffing oscillator with delayed PD control

As an application of the general methodology when \(\beta =0\), consider the harmonically forced Duffing oscillator with delayed state (proportional and derivative; PD) feedback given by the DDE

$$\begin{aligned}&\ddot{z}+2\zeta \dot{z}+z+\mu z^{3}=2 a z\left( t-\alpha \right) \nonumber \\&\qquad +2 b \dot{z}\left( t-\alpha \right) +\gamma \,\cos \left( 2\pi t/T\right) . \end{aligned}$$
(39)

Inspired by [7], for fixed \(\zeta \), \(\mu \), a, b, and \(\gamma \), we seek a delay \(\alpha \) that minimizes the maximum amplitude of oscillation along a family of periodic responses of this system under variations in the excitation period T. Since the optimization problem involves minimizing a maximum, it corresponds to the search for a saddle point in the value of the oscillation amplitude on the two-dimensional constraint manifold.

Following Sect. 2.1, let \(x_1(\tau )\doteq z(T\tau +T\phi /2\pi )\) and \(x_2(\tau )\doteq \dot{z}(T\tau +T\phi /2\pi )\) represent the displacement and velocity, respectively, on the rescaled time interval [0, 1]. The phase \(\phi \) is again to be chosen so as to shift the time on this interval when the oscillator reaches its maximum displacement to \(\tau =0\). It follows that the objective functional is given by

$$\begin{aligned} \mu _A=x_1(0) \end{aligned}$$
(40)

for solutions of (25)–(27) subject to the phase condition

$$\begin{aligned} x_2(0)=0 \end{aligned}$$
(41)

and corresponding to the vector field

$$\begin{aligned}&f(t,u,v,p)=\begin{pmatrix}u_2\\ -2\zeta u_2-u_1-\mu u_1^3\end{pmatrix}\nonumber \\&\quad +\begin{pmatrix}0\\ 2av_1+2bv_2+\gamma \cos \left( 2\pi t/T+\phi \right) \end{pmatrix}, \end{aligned}$$
(42)

where \(p=\phi \).

The partial Lagrangian for the objective functional and phase condition is

$$\begin{aligned}&L_\mathrm {opt}\left( x(\cdot ),\mu _A,\lambda _\mathrm {ph},\eta _A\right) \nonumber \\&\quad = \mu _A+\lambda _\mathrm {ph}x_2(0)+\eta _A(x_1(0)-\mu _A), \end{aligned}$$
(43)

where \(\lambda _\mathrm {ph}\) and \(\eta _A\) are additional Lagrange multipliers. This partial Lagrangian adds the term \((\eta _A, \lambda _\mathrm {ph})^\text {T}\) to the variation with respect to x(0) in (35) (first term) and results in the algebraic adjoint constraint

$$\begin{aligned} 0&=1-\eta _A, \end{aligned}$$
(44)

assuming no additional dependence of the problem Lagrangian on \(\mu _A\).

Since neither the objective functional nor the additional phase conditions depend on x evaluated at an interior point of the interval [0, 1], it follows that \(\lambda _f\) is continuous on the entire interval. This simplifies the partial Lagrangian \(L_\mathrm {BVP}\) in (29) as the two integrals with boundary \(\beta \) can be combined, and the resulting adjoint DDE contribution (33) can be applied on the combined interval \((\alpha /T,1-\alpha /T)\), such that \(\lambda _f(\tau )\) is in fact continuously differentiable on \((0,1-\alpha /T)\). Correspondingly, the middle adjoint condition in (35) can be omitted. Moreover, like in the motivating example in Sect. 2.1, it is easy to see that the rate of change of \(\mu _A=x_1(0)\) with respect to \(\delta =x_2(0)\) vanishes at \(\delta =0\). We conclude that \(\lambda _\mathrm {ph}=0\) at a stationary point of the Lagrangian. This implies that \(\lambda _{f,2}(1)=\lambda _{f,2}(0)\) and, by inspection of (33) and (34), that both components of \(\lambda _f\) are actually continuously differentiable throughout the interval [0, 1].

Since the dimension \(n_\mathrm {opt}\) of the optimization manifold equals 2, the successive continuation approach proposed by Kernévez and Doedel [11] requires multiple stages (in contrast to the motivating example in Sect. 2.1, where \(n_\mathrm {opt}=1\)): one initially optimizes only with respect to one variable, following a curve in the optimization manifold, keeping \(n_\mathrm {opt}-1\) variables fixed. At each successive stage of continuation, one releases one further optimization variable, until all variables are free. In this analysis, we propose to keep \(\alpha \) fixed during the initial stage of continuation, corresponding to the imposition of a constraint on the set of unknowns. To this end, we consider the additional partial Lagrangian

$$\begin{aligned} L_\mathrm {sc}(\alpha ,\mu _\alpha ,\eta _\alpha )=\eta _\alpha (\alpha -\mu _\alpha )\text{. } \end{aligned}$$
(45)

This partial Lagrangian adds the constraint

$$\begin{aligned} \alpha =\mu _\alpha \end{aligned}$$
(46)

and the algebraic adjoint equation (for vanishing variation with respect to \(\mu _\alpha \))

$$\begin{aligned} 0&=\eta _\alpha , \end{aligned}$$
(47)

and adds \(\eta _\alpha \) to the adjoint variations with respect to \(\alpha \) in (36). The total problem Lagrangian is now given by

$$\begin{aligned}&L\left( x(\cdot ),\alpha ,T,p,\mu _A,\mu _\alpha , \lambda _f(\cdot ),\lambda _\mathrm {bc},\lambda _\mathrm {ph},\eta _A, \eta _\alpha \right) \nonumber \\&\quad =L_\mathrm {BVP}\left( x(\cdot ),\alpha ,T,p,\lambda _f(\cdot ), \lambda _\mathrm {bc}\right) \nonumber \\&\qquad +L_\mathrm {opt}\left( x(\cdot ),\mu _A,\lambda _\mathrm {ph}, \eta _A\right) +L_\mathrm {sc}(\alpha ,\mu _\alpha ,\eta _\alpha ). \end{aligned}$$
(48)

The necessary conditions for an extremum of the total Lagrangian are then given by (i) the original differential equations and boundary conditions, (25)–(27), (40), (41), and (46), and (ii) the various adjoint equations, including (44) and (47), assembled in stages as constraints and variables are added, setting the sums of all resulting contributions equal to 0. Although we anticipate that \(\lambda _\mathrm {ph}\) will equal 0 throughout the analysis, we keep \(\lambda _\mathrm {ph}\) as an unknown and monitor its value during continuation.

As in the previous section, we may locate an extremum of L by several successive stages of continuation, in each stage omitting one or both of the adjoint conditions (44) and (47). In particular, by holding \(\mu _\alpha \) fixed and letting \(\eta _A\) vary freely, we may arrive at a solution with \(\eta _A=1\) in two stages of continuation: first, by continuing along a one-dimensional manifold with vanishing Lagrange multipliers, and next by branch switching at a local extremum of \(\mu _A\) to a secondary branch along which only the Lagrange multipliers vary and, in fact, do so proportionally to \(\eta _A\). A final stage of continuation then proceeds from the point on this second manifold where \(\eta _A=1\), but this time with \(\eta _A\) fixed at 1 and \(\mu _\alpha \) free to vary. A sought extremum is obtained when \(\eta _\alpha =0\).

An example of such an analysis for the case when \(\zeta =0.05\), \(\mu =0.05\), \(a=0.05\), \(b=-0.05\), and \(\gamma =0.5\) is shown in Fig. 4 (projected into the \((\alpha , 2\pi /T,\mu _A)\) space). Here, the full integro-differential boundary-value problem is discretized and analyzed using the coco [18] package following the methodology discussed in [2] in terms of continuous, piecewise-polynomial approximants on a uniform partition of every solution segment into \(N=10\) mesh intervals, resulting in a large system of nonlinear algebraic equations. The successive continuation approach then proceeds along the following stages:

  • Initial guess An initial solution guess for \(x(\tau )\) near the first manifold is first constructed using direct simulation with \(\alpha =0.1\) and \(T=2\pi \), after which \(\phi \) is adjusted such that the maximum of \(x_1\) occurs at \(\tau \approx 0\). We finally let \(\mu _A=x_1(0)\) and \(\mu _\alpha =\alpha \).

  • Stage 1: Continuation along manifold with vanishing Lagrange multipliers The delay \(\alpha \) is held constant by fixing \(\mu _\alpha \) at its initial value. Continuation proceeds along the blue curve in Fig. 4, monitoring for branch points (coincident with extrema in \(\mu _A\) up to discretization errors).

  • Stage 2: Continuation along manifold with varying Lagrange multipliers Branch off at the discovered branch point (labeled BP in Fig. 4) with \(\mu _\alpha \) still fixed, stopping when \(\eta _A\) reaches 1. During this continuation all primary variables \(x(\cdot )\), \(\phi \), T, \(\alpha \) stay constant. Only Lagrange multipliers change their values. This continuation does not change any coordinates in Fig. 4 (we remain at the point BP).

  • Stage 3: Continuation with varying\(\mu _\alpha \). Fix \(\eta _A\) at 1 and allow \(\mu _\alpha \) (and, consequently, \(\alpha \)) to vary. Continue while monitoring \(\eta _\alpha \) for zero crossings (red curve in Fig. 4). The point where \(\eta _\alpha =0\) along the red curve is labeled “Local Optimum.” At this point, all necessary conditions for a stationary point of L are satisfied, including \(\eta _A=1\) and \(\eta _\alpha =0\).

Fig. 4
figure 4

Optimization of the displacement amplitude along periodic orbits of the harmonically excited Duffing oscillator with \(\zeta =0.05\), \(\mu =0.05\), \(a=0.05\), \(b=-0.05\), and \(\gamma =0.5\) under variations in \(\alpha \) and T. Three successive stages of continuation connect the sought saddle point with an initial solution guess with vanishing Lagrange multipliers. Stages 1 (blue) and 3 (red) described in the text are visible in the \((\alpha ,2\pi /T,\mu _A)\) space. In Stage 1, a peak in the displacement amplitude is approximately detected in close proximity to a branch point for the corresponding continuation problem. The second stage involves branch switching to a branch along which only the Lagrange multipliers vary (not visible). The red curve shows the final stage of continuation with fixed \(\eta _{A}=1\). The optimal delay and corresponding period obtained at the terminal point with \(\eta _\alpha =0\) equal 0.7824 and 5.88, respectively. At this point \(\mu _A=1.9852\). (Color figure online)

The end point of stage 3 corresponds to a critical point at \(\alpha \approx 0.7824\), \(\phi \approx 1.488\), and \(T\approx 5.88\) (which Fig. 4 confirms to be a saddle point). We may compare the resulting optimal delay with the prediction from a first-order multiple-scales perturbation analysis for the weakly nonlinear (small \(\mu \)), weakly damped (small \(\zeta \)), and weakly forced (small \(\gamma \)) case, which predicts a maximal (with respect to T) response amplitude

$$\begin{aligned} \frac{\gamma }{2|\zeta +a\sin \alpha -b\cos \alpha |}, \end{aligned}$$
(49)

(independent of \(\mu \), see the appendix for intermediate steps; also see [7, 17]). The computed optimal delay \(\alpha \approx 0.7824\) is in close agreement with the predicted optimal delay \(\pi /4\approx 0.7854\) obtained from (49) for the case that \(b=-a\). The optimal displacement profile \(x_1(\tau )\) and the components of \(\lambda _f(\tau )\) are shown in Fig. 5. The top panel shows close agreement between the results obtained using continuation and the harmonic response obtained from the perturbation analysis, at the computed optimal values of \(\alpha \), T, and \(\phi \). Panel (b) of Fig. 5 shows the functional Lagrange multipliers \(\lambda _f\), confirming that they are approximately smooth in this example (since the objective does not depend on \(\beta \in (0,1)\)) but with \(\lambda _{f,1}(1)\ne \lambda _{f,1}(0)\) and \(\lambda _{f,2}(1)\approx \lambda _{f,2}(0)\) (since the objective functional and the phase constraints depend on x(0) and \(\lambda _\mathrm {ph}\approx 0\)).

Fig. 5
figure 5

a\(x_1(\tau )\) and b\(\lambda _{f,1}(\tau )\) and \(\lambda _{f,2}(\tau )\) at the terminal point of the third stage of continuation illustrated in Fig. 4. The upper panel shows a comparison between the numerical solutions obtained using continuation at the computed optimal value of \(\alpha \), and a first-order multiple-scales perturbation analysis at the predicted optimal value of \(\alpha \)

Further comparisons between the results obtained using the successive continuation approach and those predicted by the perturbation analysis are shown in Figs. 6 and 7 for the case when the oscillator is only subjected to displacement feedback, i.e., when \(b=0\), with weak (\(\mu =0.05\)) and strong (\(\mu =1\)) nonlinearity, respectively. In each case, the perturbation analysis predicts a saddle in the response amplitude for \(\alpha =\pi /2\approx 1.5708\), while the computational results are \(\alpha \approx 1.4712\) and 0.8712, respectively. For the case of weak nonlinearity depicted in Fig. 6, there is still close agreement between the optimal time histories for \(x_1(\tau )\), while this is no longer true for the case of strong nonlinearity shown in Fig. 7. The frequency response curves shown in the lower panels of Figs. 6 and 7 were obtained using numerical continuation for the computed and predicted critical values of \(\alpha \). In the case of the weak nonlinearity, we note a weak dependence on the location and magnitude of the peak on the value of the delay, while the differences are stark in the case of the strong nonlinearity. In the latter case, the optimal delay predicted by the perturbation analysis produces a peak amplitude more than \(50\%\) larger than that obtained using the numerical method.

Fig. 6
figure 6

Optimization of the displacement amplitude along periodic orbits of the harmonically excited, weakly nonlinear Duffing oscillator with \(\zeta =0.05\), \(\mu =0.05\), \(a=0.05\), \(b=0\), and \(\gamma =0.5\) under variations in \(\alpha \) and T. a Comparison of the displacement profile obtained from continuation at the computed optimal delay \(\alpha \approx 1.4712\) and period \(T\approx 5.7151\) with the results predicted by perturbation analysis. b Frequency response diagrams for the computed and predicted critical delay values 1.4712 and \(\pi /2\), respectively

Fig. 7
figure 7

Optimization of the displacement amplitude along periodic orbits of the harmonically excited, strongly nonlinear Duffing oscillator with \(\zeta =0.05\), \(\mu =1\), \(a=0.05\), \(b=0\), and \(\gamma =0.5\) under variations in \(\alpha \) and T. a Comparison of the displacement profile obtained from continuation at the computed optimal delay \(\alpha \approx 0.8712\) and period \(T\approx 3.4192\) with the results predicted by perturbation analysis. b Frequency response diagrams for the computed and predicted critical delay values 0.8712 and \(\pi /2\), respectively

3.3 Quasiperiodic orbits

We proceed to consider the problem of optimizing a scalar-valued objective functional on a family of quasiperiodic solutions of (24), for which there exists an irrational rotation number\(\rho \) and a smooth function \(Z:\mathbb {S}\times \mathbb {S}\rightarrow \mathbb {R}^n\) (here, \(\mathbb {S}\) denotes the unit circle) such that

$$\begin{aligned} z(t)= & {} Z\left( \theta _1(t),\theta _2(t)\right) ,\,\dot{\theta }_1=\rho \Omega ,\,\text { and }\nonumber \\ \dot{\theta }_2= & {} \Omega \doteq 2\pi /T \end{aligned}$$
(50)

in terms of the period T of the vector field f in its first argument. Let subscripts \(_{\theta _1}\) and \(_{\theta _2}\) denote partial derivatives with respect to the corresponding arguments. Substitution into the governing equation then yields the partial differential equation (PDE)

$$\begin{aligned} \rho \Omega Z_{\theta _{1}}+\Omega Z_{\theta _{2}}= f\left( t,Z,Z\left( \theta _{1}-\rho \Omega \alpha ,\theta _{2}-\Omega \alpha \right) ,p\right) \end{aligned}$$
(51)

on the two-dimensional torus \(\mathbb {S}\times \mathbb {S}\).

We decompose this PDE along its characteristics. To this end, consider the continuous function \(V:\mathbb {S}\times [0,1]\rightarrow \mathbb {R}^n\) given by

$$\begin{aligned} V(\varphi ,\tau )\doteq Z(\varphi +2\pi \rho \tau ,2\pi \tau ), \end{aligned}$$
(52)

such that \(\tau =t/T\), \(\theta _1(0)=\varphi \), and without loss of generality \(\theta _2(0)=0\). Shifting and wrapping of arguments between and along characteristics will occur several times below. To simplify notation, suppose that \(T>\alpha \) and introduce the wrapping operation W for the function V on \(\mathbb {S}\times [0,1]\) as

$$\begin{aligned} \left[ W_a^j V\right] (\varphi ,\tau )=V(\varphi -2\pi j\rho ,\tau -a+j),\,j=-1,0,1 \end{aligned}$$
(53)

for \(\tau -a+j\in [0,1]\) and all \(\varphi \in \mathbb {S}\). It follows by periodicity that

$$\begin{aligned} Z(\varphi +2\pi \rho (\tau -a),2\pi (\tau -a))=\left[ W_a^j V\right] (\varphi ,\tau ) \end{aligned}$$
(54)

for \(\tau -a+j\in [0,1]\) and all \(\varphi \in \mathbb {S}\). Differentiation and use of (51) then implies that

$$\begin{aligned}&V_\tau =Tf\left( T\tau ,V,W_{\alpha /T}^1 V,p\right) , (\varphi ,\tau )\in \mathbb {S}\times \left( 0,\alpha /T\right) , \end{aligned}$$
(55)
$$\begin{aligned}&V_\tau =Tf\left( T\tau ,V,W_{\alpha /T}^0 V,p\right) , (\varphi ,\tau )\in \mathbb {S}\times \left( \alpha /T,1 \right) , \end{aligned}$$
(56)

along with the boundary conditions

$$\begin{aligned} V(\varphi ,1)-V(\varphi +2\pi \rho ,0)=0,\,\varphi \in \mathbb {S}. \end{aligned}$$
(57)

Equations (55)–(57) are a family of coupled DDE BVPs in time \(\tau \), parametrized by the continuous periodic angle \(\varphi \). A family of orbit segments \(\mathbb {S}\times [0,1]\ni (\varphi ,\tau )\mapsto V(\varphi ,\tau )\in \mathbb {R}^n\) solving this family of BVPs then spans the sought quasiperiodic invariant torus. Such a family is unique only up to a shift of its argument \(\varphi \in \mathbb {S}\). We isolate a locally unique solution by introducing the integral phase condition

$$\begin{aligned} \int _0^{2\pi }\left( V(\varphi ,0)-V^*(\varphi )\right) ^\text {T} V^{*}_\varphi (\varphi )\,\mathrm {d}\varphi =0 \end{aligned}$$
(58)

in terms of a given continuously differentiable reference function \(V^*:\mathbb {S}\rightarrow \mathbb {R}^n\) that is either fixed throughout the analysis or updated as appropriate. For fixed values of the problem delay \(\alpha \), excitation period T, and problem parameters p, the resultant integro-differential BVP (55)–(58) defining the quasiperiodic response is over-determined (recall that the rotation number \(\rho \) is fixed) such that one has to leave at least one system parameter free to vary to obtain isolated solutions. For example, for fixed \(\alpha \), we thus expect to obtain a one-dimensional manifold of quasiperiodic invariant tori under simultaneous variations in T and a single element of p.

We now apply the construction of the Lagrangian and adjoint equations to this family of DDE BVPs to formulate optimization problems with constraints of the form (55)–(58), following the procedure from Sect. 3.1. We assume that neither the objective functional nor any additional constraints depend on V evaluated for \(\tau \) on the interior of the interval [0, 1], and that they only depend on V on the boundaries \(\tau =0\) and \(\tau =1\) through integrals over \(\varphi \). In this case, the Lagrange multipliers \(\lambda _f\) for the DDE constraint (55) will be continuous on the domain \(\mathbb {S}\times [0,1]\) (including periodicity in their first argument \(\varphi \)). The partial Lagrangian for constraints (55)–(58) is then given by

$$\begin{aligned}&L_\mathrm {BVP}(V(\cdot ,\cdot ),\alpha ,T,p,\lambda _f(\cdot ,\cdot ),\lambda _\mathrm {rot}(\cdot ),\lambda _\mathrm {ph}) \nonumber \\&\quad =\int \limits _{\varphi } \int \limits _{0}^{\alpha /T}\mathrm {d}\tau \left[ \lambda _{f}^\text {T}\left( V_\tau -Tf_{1}\right) \right] \nonumber \\&\qquad +\int \limits _{\varphi } \int \limits _{\alpha /T}^{1-\alpha /T}\mathrm {d}\tau \left[ \lambda _{f}^\text {T}\left( V_\tau -Tf_{0}\right) \right] \nonumber \\&\qquad +\int \limits _{\varphi }\int \limits _{1-\alpha /T}^{1}\mathrm {d}\tau \left[ \lambda _{f}^\text {T}\left( V_\tau -Tf_{0}\right) \right] \nonumber \\&\qquad +\int \limits _{\varphi }\lambda _{\mathrm {rot}}^\text {T}(\varphi )\left( V\left( \varphi ,1\right) -V\left( \varphi +2\pi \rho ,0\right) \right) \,\nonumber \\&\qquad +\lambda _\mathrm {ph}\int \limits _{\varphi }\left( V(\varphi ,0)-V^*(\varphi )\right) ^\text {T} V^{*}_\varphi (\varphi ), \end{aligned}$$
(59)

where we abbreviate \(\int _{\varphi }=\int _0^{2\pi }\mathrm {d}\phi \) and, similarly to Sect. 3.1, let \(f_j(\varphi ,\tau )=f(T\tau , V,W^j_{\alpha /T} V,p)\). The vector-valued functions \(\lambda _{f}(\varphi ,\tau )\) and \(\lambda _\mathrm {rot}(\varphi )\), and the scalar \(\lambda _\mathrm {ph}\) are the Lagrange multipliers associated with the imposition of the differential equations (55) and (56), boundary conditions (57), and the integral phase condition (58), respectively. Each integrand is assumed to be continuously differentiable on the corresponding interval, and \(\lambda _f\) and \(\lambda _\mathrm {rot}\) are assumed to be continuous and, hence, periodic in \(\varphi \) for all \(\tau \). It is again straightforward to show that \(\lambda _f\) must be continuous in \(\tau \) on \(\tau =\alpha /T\) and \(\tau =1-\alpha /T\) at a stationary point of the total Lagrangian. In this case, \(\lambda _f\) is continuously differentiable in \(\tau \) everywhere except at \(\tau =1-\alpha /T\), where a slope discontinuity is anticipated from the boundary conditions (57).

Analogously to Sect. 3.1, consider the notation

$$\begin{aligned} f_{j,k}(\varphi ,\tau )&=\partial _kf(T\tau ,V(\varphi ,\tau ),[W^j_{\alpha /T} V](\varphi ,\tau ),p), \end{aligned}$$
(60)
$$\begin{aligned} f_{j,q}(\varphi ,\tau )&=\frac{\mathrm {d}}{\mathrm {d}\, q}f\left( T\tau ,V(\varphi ,\tau ),[W^j_{\alpha /T} V](\varphi ,\tau ),p\right) , \end{aligned}$$
(61)

for \(j=0,1\) and \(q=\alpha ,T\). Then, the contributions to the necessary adjoint conditions for a stationary point of the total Lagrangian are given by

$$\begin{aligned}&-\lambda _{f,\tau }^\text {T}-T\lambda _{f}^\text {T} f_{1,2} -T\left( W^0_{-\alpha /T}\,\lambda _{f}\right) ^\text {T} W^0_{-\alpha /T}f_{0,3} \end{aligned}$$
(62)

for variations with respect to \(V(\varphi ,\tau )\) on \((\varphi ,\tau ) \in \mathbb {S}\times \left( 0,\alpha /T\right) \);

$$\begin{aligned}&-\lambda _{f,\tau }^\text {T}-T\lambda _{f}^\text {T} f_{0,2}-T\left( W^0_{-\alpha /T}\,\lambda _{f}\right) ^\text {T} W^0_{-\alpha /T} f_{0,3} \end{aligned}$$
(63)

for variations with respect to \(V(\varphi ,\tau )\) on \((\varphi ,\tau ) \in \mathbb {S}\times \left( \alpha /T,1-\alpha /T\right) \);

$$\begin{aligned}&-\lambda _{f,\tau }^\text {T}-T\lambda _{f}^\text {T} f_{0,2}-T\left( W^{-1}_{-\alpha /T}\,\lambda _{f}\right) ^\text {T} W^{-1}_{-\alpha /T}f_{1,3} \end{aligned}$$
(64)

for variations with respect to \(V(\varphi ,\tau )\) on \((\varphi ,\tau ) \in \mathbb {S}\times \left( 1-\alpha /T,1\right) \);

$$\begin{aligned} \lambda _{f}^\text {T}\left( \varphi ,0\right) +\lambda _\mathrm {rot}^\text {T}\left( \varphi -2\pi \rho \right) +\lambda _\mathrm {ph} V^{*\top }_\varphi (\varphi ) \end{aligned}$$
(65)

for variations with respect to \(V(\varphi ,0)\) on \(\varphi \in \mathbb {S}\);

$$\begin{aligned} \lambda _{f}^\text {T}\left( \varphi ,1\right) +\lambda _\mathrm {rot}^\text {T} \left( \varphi \right) \end{aligned}$$
(66)

for variations with respect to \(V(\varphi ,1)\) on \(\varphi \in \mathbb {S}\);

$$\begin{aligned} -\int \limits _{\varphi }\int \limits _{0}^{\alpha /T}\mathrm {d}\tau \left[ \lambda _f^\text {T} Tf_{1,\alpha }\right] - \int \limits _{\varphi }\int \limits _{\alpha /T}^{1}\mathrm {d}\tau \left[ \lambda _f^\text {T} Tf_{0,\alpha }\right] \end{aligned}$$
(67)

for variations with respect to \(\alpha \);

$$\begin{aligned}&-\int \limits _{\varphi }\int \limits _{0}^{\alpha /T}\mathrm {d}\tau \left[ \lambda _f^\text {T}\left( Tf_{1,T}+f_{1}\right) \right] \nonumber \\&-\int \limits _{\varphi }\int \limits _{\alpha /T}^{1}\mathrm {d}\tau \left[ \lambda _f^\text {T}\left( Tf_{0,T}+f_{0}\right) \right] \end{aligned}$$
(68)

for variations with respect to T; and

$$\begin{aligned} -\int \limits _{\varphi }\int \limits _{0}^{\alpha /T}\mathrm {d}\tau \left[ \lambda _f^\text {T} Tf_{1,4}\right] -\int \limits _{\varphi }\int \limits _{\alpha /T}^{1}\mathrm {d}\tau \left[ \lambda _f^\text {T} Tf_{0,4}\right] \end{aligned}$$
(69)

for variations with respect to p.

3.4 A Hopf unfolding with delay and forcing

Consider, for example, the problem of finding a local maximum in \(\omega \) along a family of quasiperiodic invariant tori of the vector field

$$\begin{aligned}&f\left( t,u,v, p\right) =\left( \begin{array}{c} -\omega u_{2} +v_{1}\left( 1+r\left( \cos 2\pi t/T-1\right) \right) \\ \omega u_{1} +v_{2}\left( 1+r\left( \cos 2\pi t/T-1\right) \right) \end{array}\right) , \end{aligned}$$
(70)

where \(r=\sqrt{u_{1}^{2}+u_{2}^{2}}\), \(\alpha =1\), and \(p=\omega \). Notably, an example in the tutorial for the coco trajectory segment toolbox [18] shows that no such local maximum exists when \(\alpha =0\), since then \(\omega T=2\pi \rho \). In the present case, we consider the optimization problem

$$\begin{aligned} \text{ maximize }\quad \mu _\omega =\omega \end{aligned}$$
(71)

subject to constraints (55)–(58) (the coupled DDEs with boundary conditions and phase condition, depending on \(\varphi \)). The problem Lagrangian is then given by

$$\begin{aligned}&L(V(\cdot ,\cdot ),T,p,\mu _\omega ,\lambda _f(\cdot ,\cdot ), \lambda _\mathrm {rot}(\cdot ),\lambda _\mathrm {ph},\eta _\omega )\nonumber \\&\quad =\mu _\omega +\eta _\omega (\omega -\mu _\omega )\nonumber \\&\qquad +L_\mathrm {BVP}\left( V(\cdot ,\cdot ),1,T,p,\lambda _f(\cdot ,\cdot ), \lambda _\mathrm {rot}(\cdot ),\lambda _\mathrm {ph}\right) , \end{aligned}$$
(72)

where \(L_\mathrm {BVP}\) is given in (59) and \(\eta _\omega \) is the additional Lagrange multiplier. The necessary conditions for an extremum of the total Lagrangian are then given by (i) the original differential equations and boundary conditions (55)–(58); (ii) the adjoint conditions (excluding (67)) obtained by appending \(\eta _\omega \) to the variation with respect to p (69) and setting all the resulting contributions equal to 0; and (iii) the condition that \(\eta _\omega =1\).

As in previous examples, we immediately note that \(\lambda _\mathrm {ph}\) must equal 0 at a stationary point of the Lagrangian, since the objective function is clearly independent of the particular choice of family \((\varphi ,\tau )\mapsto V(\varphi ,\tau )\) selected by the phase condition. The adjoint boundary conditions (65) and (66) then imply that

$$\begin{aligned} \lambda _f^\text {T} (\varphi ,1)-\lambda _{f}^\text {T}(\varphi +2\pi \rho ,0)=0. \end{aligned}$$
(73)

Moreover, direct computation using (70) and the boundary condition (57) shows that

$$\begin{aligned} f_{0,3}(\varphi ,1)-f_{1,3}(\varphi +2\pi \rho ,0)=0. \end{aligned}$$
(74)

It follows from (63) and (64) that

$$\begin{aligned}&\lambda _{f,\tau }^\text {T}(\varphi ,1-1/T)_+ - \lambda _{f,\tau }^\text {T}(\varphi ,1-1/T)_- =0, \end{aligned}$$
(75)

i.e., that \(\lambda _f\) is continuously differentiable in \(\tau \) on the entire interval [0, 1].

Fig. 8
figure 8

One-dimensional manifold obtained from the first stage of continuation along a family of approximate quasiperiodic invariant tori with vanishing Lagrange multipliers for the case that \(\rho \approx 0.6618\). The local maximum \(\mu _\omega \approx 0.43685\) when \(T\approx 5.3153\) approximately coincides with a branch point (BP). Solid and dashed lines denote dynamically stable and unstable tori, respectively

Fig. 9
figure 9

a Optimal quasiperiodic invariant torus and b corresponding representation of \(\lambda _f\) obtained at the terminal point (\(\eta _\omega =1\)) of the second stage of continuation with \(\rho \approx 0.6618\). c The components of \(\lambda _\mathrm {rot}\) at this point. Solid gray curves in a and b denote the discretization of \(V(\varphi ,\tau )\) and \(\lambda _f(\varphi ,\tau )\) using trajectory segments based at \(\varphi =(i-1)/11\), for \(i=1,\ldots ,11\)

We proceed to locate an extremum by applying the successive continuation technique to the set of equations obtained by omitting the trivial adjoint condition that \(\eta _\omega =1\). To this end, we approximate \(V(\varphi ,\tau )\), \(\lambda _f(\varphi ,\tau )\), and \(\lambda _\mathrm {rot}(\varphi )\) by truncated Fourier series in \(\varphi \) with \(\tau \)-dependent Fourier coefficient functions, as appropriate, approximated by continuous piecewise-polynomial interpolants on the interval [0, 1]. Although we anticipate that \(\lambda _\mathrm {ph}\) will equal 0 throughout continuation, we keep \(\lambda _\mathrm {ph}\) as an unknown and monitor its value during continuation. We first continue along a one-dimensional manifold along which the Lagrange multipliers always equal 0, and then branch switch at a local maximum of \(\mu _\omega \) to a secondary branch along which the family V remains unchanged, while the Lagrange multipliers vary linearly in \(\eta _\omega \). The solution to the necessary conditions for a local stationary point is then obtained once \(\eta _\omega =1\) along the secondary branch.

The results of such an analysis using coco are shown in Figs. 8 and 9 for the case that \(\rho \approx 0.6618\). Here, dependence on \(\varphi \) is approximated using a Fourier series truncated at the fifth harmonic corresponding to 11 trajectory segments on the torus based at \(\varphi =(i-1)/11\), \(i=1,\ldots ,11\). Each \(\tau \)-dependent Fourier coefficient is discretized using polynomials of degree 4 on a uniform mesh with 10 intervals. The one-dimensional family of quasiperiodic orbits in Fig. 8 along the first manifold with vanishing Lagrange multipliers indicates the existence of a local maximum in \(\mu _\omega \approx 0.43685\) for \(T\approx 5.3153\). Branch switching from the nearby branch point (as before, exact coincidence is lost due to discretization) and continuing until \(\eta _\omega =1\) yields the approximate torus and the corresponding Lagrange multipliers \(\lambda _f\) and \(\lambda _\mathrm {rot}\) shown in Fig. 9.

As an aside, direct numerical simulation using initial conditions predicted by the continuation analysis suggests that quasiperiodic tori found on the lower half of the one-dimensional family shown in Fig. 8 are stable to sufficiently small perturbations, while the tori found on the upper half are unstable, with a critical loss of stability coincident with the peak value of \(\mu _\omega \).

4 Conclusions

The various examples in previous sections illustrate the successful application to the case with single time delays of the general methodology to optimization along implicitly defined solutions to integro-differential boundary-value problems first proposed by Kernevez and Doedel [11] for ordinary differential equations. Here, the partial Lagrangian approach introduced in [12] was used to derive adjoint conditions that were linear and homogeneous in the unknown Lagrange multipliers. This allowed a search for local extrema to proceed along a connected sequence of one-dimensional manifolds of solutions to the necessary conditions for such extrema minus the trivial algebraic adjoint conditions on a subset of the Lagrange multipliers: first, along a branch with vanishing Lagrange multipliers, then switching to a branch with linearly varying Lagrange multipliers, and then along additional branches until all the previously omitted trivial algebraic adjoint conditions were satisfied.

In contrast to the case of ordinary differential equations, the presence of time delays introduces potential discontinuities that must be accounted for in any numerical solution strategy. By the properties of differential equations with time-shifted arguments, such discontinuities propagate across time, gaining an order of continuity for each iteration. Here, we have only accounted for zeroth- or first-order discontinuities in the formulation of the governing boundary-value problems. On each segment along which a function was shown to be continuously differentiable, we have approximated such a function by a continuous piecewise-polynomial function of degree 4 in each mesh interval, ignoring continuity in the first derivative across mesh boundaries or discontinuities of order two or higher within each mesh interval. The piecewise-polynomial approximants have been used to impose a discretization of the governing differential equations at a set of collocation nodes within each interval and to evaluate functions with time-shifted arguments on the same or other intervals. Such a collocation strategy is consistent with the approach in [3], and there compared to an alternative mesh strategy that depends on the delay. We have not undertaken a detailed analysis of the sensitivity of the results to the numerical mesh or polynomial degree. Notably, while we rely in this paper invariably on uniform meshes, it is common to consider adaptive meshes for which the number of intervals and their relative size may change during continuation. We leave such an implementation for future work.

In all the examples, a Lagrange multiplier associated with a phase condition was found to equal 0 on a local extremum of the corresponding Lagrangian. As stated previously, we nevertheless retained this Lagrange multiplier as an unknown and monitored its value during continuation. Experiments with the number of mesh intervals were used to determine whether this value was effectively 0 also in the computational analysis. An alternative would have been to eliminate this variable from the set of adjoint equations while simultaneously eliminating one of the adjoint conditions. In a single instance, this may indeed be useful, but when relying on a general-purpose implementation as envisioned in a planned future implementation of coco, it is better to retain the variable and use its numerical value as an indicator of the accuracy of the solution.

There are a number of directions to go in future work. These include consideration of circumstances in which the ratio \(\alpha /T\) violates one or several of the inequalities assumed in the previous sections during continuation. Such violations may necessitate a piecewise definition of the Lagrangian across parameter space with different segmentations of the governing differential equations in each region. Problems with multiple delays, as well as problems with state- or time-dependent delays could also be explored as motivated by particular applications.