Theory and Modern Applications

# Sweep algorithm for solving optimal control problem with multi-point boundary conditions

## Abstract

The sweep algorithm for solving optimal control problem with multi-point boundary conditions is offered. According to this algorithm, the search of initial conditions is reduced to the solution of the corresponding system of linear algebraic equations. A similar algorithm is proposed for the discrete case.

## 1 Introduction

To solve the control problem with two-point boundary conditions, different computational algorithms have been developed: those increasing the initial system dimension [1] and based on solutions of the corresponding Hamiltonian equations [2] as well as the ones not increasing the initial problem dimensions [3, 4].

On the example of construction of the program trajectory and control for biped apparatus (PA) [3], some difficulties are demonstrated in application of algorithms suggested in [1]. These difficulties are mainly related to bad conditionality of the Hamiltonian matrix of the corresponding linear algebraic equations.

That is why in [2] other methods as well as sweep method are suggested for solving the problem under consideration.

Different situation arises in the optimization problems with multi-point boundary conditions. Namely, in this case the Lagrange multiplier becomes discontinuous at the internal points, and direct application of methods of two-point boundary value problems to optimization problems with multi-point boundary conditions is not possible.

In the paper the modified sweep method is used for solving of the optimal control problem with multi-point boundary conditions. Both the continuous and discrete cases are considered.

## 2 Statement of the problem (the continuous case)

Let us assume that some process is described by the equation

$$\dot{x}(t)=F(t)x(t)+G(t)U(t)+v(t),\quad t\in [0,T ],$$
(1)

with multi-point boundary conditions

$$\sum_{i=0}^{p} \Phi_{i} x (t_{i} ) =q,$$
(2)

where $$0=t_{0} < t_{1} <\cdots<t_{i} <\cdots<t_{p-1} <t_{p} =T$$; $$x (t )$$ is n-dimensional phase vector; $$u (t )$$ is m-dimensional control vector; $$v (t )$$ is n-dimensional vector; $$F (t )$$, $$G(t)$$ are matrix functions of $$n\times n$$ and $$n\times m$$ dimensions, correspondingly; $$\Phi_{i}$$, $$i=\overline{1, p}$$, are matrices of dimension $$k\times n$$; q is k-dimensional vector.

We need to find a control $$u(t)$$ and corresponding trajectory $$x(t)$$ that minimize the functional

$$J=\frac{1}{2} \int_{0}^{T} \bigl[x'(t)Q(t)x(t)+u'(t)C(t)u(t) \bigr]\,dt ,$$
(3)

where $$Q(t)=Q'(t)\ge0$$, $$C(t)=C'(t)>0$$ are the matrices of dimensions $$n\times n$$ and $$m\times m$$, correspondingly.

Then the corresponding Euler-Lagrange equation will be as follows:

\begin{aligned} &\dot{x} (t )=F (t )x (t )-M (t )\lambda (t )+v (t ), \\ &\dot {\lambda} (t )=-Q (t )x (t )-F' (t )\lambda (t ), \\ &\lambda (t_{0} )=\lambda (0 )=-\Phi_{p}^{\prime} \gamma, \\ &\lambda (t_{i} +0 )=\lambda (t_{i} -0 )-\Phi_{p}^{\prime} \gamma, \quad i=\overline{1,p-1}, \\ &\lambda (t_{p} )=\lambda (T )=\Phi_{p}^{\prime} \gamma, \end{aligned}
(4)

where $$M (t )=-C^{-1} (t )\lambda' (t )G (t )$$; and $$\lambda (t )$$, γ are Lagrange multipliers.

Sweep method

The essence of the proposed method is that Lagrange multiplier $$\lambda (t )$$ is represented as

$$\lambda (t )=S (t )x (t )+N (t )\gamma+\omega (t ),\quad t\in [0,t ],$$
(5)

where $$S (t )$$, $$N (t )$$ and $$\omega (t )$$ are the unknown functions. Substituting expression (5) into equation (4), after some operations, we obtain the following system of differential equations for determining $$S (t )$$, $$N (t )$$ and $$\omega (t )$$:

\begin{aligned} &\dot{S} (t )=-F' (t )S (t )-S (t )F (t )+S (t )M (t )S (t )-Q (t ), \\ &\dot{N} (t )= \bigl[S (t )M (t )-F' (t ) \bigr]N (t ), \\ &\dot{\omega} (t )= \bigl[S (t )M (t )-F' (t ) \bigr]\omega (t )-S (t )v (t ). \end{aligned}
(6)

Considering the condition $$\lambda (T )=\Phi_{p} ^{\prime} \gamma$$ in (6), we obtain

$$S (t )x (T )+N (T )\gamma+\omega (T )=\Phi_{p} ^{\prime} \gamma.$$

Since the functions $$x (t )$$ and Lagrange multiplier γ are arbitrary, we obtain the following initial conditions at the point $$t=T$$:

$$S (T )=0,\qquad N (T )=\Phi_{p}^{\prime} ,\qquad \omega (T )=0.$$

Now, considering $$t=t_{0}$$ in (5) and the condition $$\lambda (t_{p} )=-\Phi_{0} ^{\prime}$$ in (4), we obtain

$$\lambda (t_{0} )=S (t_{0} )x (t_{0} )+N (t_{0} )\gamma+\omega (t_{0} )=-\Phi_{0} ^{\prime} \gamma,$$

or the following equations to determine the unknown $$x (t_{0} )$$ and γ:

$$S (t_{0} )x (t_{0} )+ \bigl[N (t_{0} )+\Phi_{0} ^{\prime} \bigr]\gamma=-\omega (t_{0} ).$$
(7)

Then, from the condition $$\lambda (t_{i} +0 )=\lambda (t_{i} -0 )-\Phi_{i} ^{\prime} \gamma$$ in (4), as well as from the equalities

\begin{aligned}& \lambda (t_{i} +0 )=S (t_{i} +0 )x (t_{i} )+N (t_{i} +0 )\gamma+\omega (t_{i} +0 ), \\& \lambda (t_{i} -0 )=S (t_{i} -0 )x (t_{i} )+N (t_{i} -0 )\gamma+\omega (t_{i} -0 ), \end{aligned}

we obtain

\begin{aligned} &S (t_{i} +0 )x (t_{i} )+N (t_{i} +0 )\gamma + \omega (t_{i} +0 )\\ &\quad=S (t_{i} -0 )x (t_{i} )+N (t_{i} -0 )\gamma+ \omega (t_{i} -0 )-\Phi_{i} ^{\prime} \gamma. \end{aligned}

Hence we obtain

\begin{aligned} &S (t_{i} +0 )=S (t_{i} -0 ), \\ &\omega (t_{i} +0 )=\omega (t_{i} -0 ),\\ &N (t_{i} +0 )=N (t_{i} -0 )-\Phi_{i} ^{\prime}. \end{aligned}
(8)

These equations mean that the functions $$S (t )$$, $$\omega (t )$$ are continuous and the function $$N (t )$$ is discontinuous at the points $$t=t_{i}$$.

Now, as in the case of two points, it can be shown that

$$\Phi_{p} x (T )=N' (t )x (t )+u (t )\gamma+W (t )$$

at $$t\in (t_{p-1} ,t_{p} )$$. Then at $$t=t_{p-1}$$ we obtain

$$\Phi_{p} x (T )=N' (t_{p-1} +0 )x (t_{p-1} )+u (t_{p-1} +0 )\gamma+W (t_{p-1} +0 ).$$

Further, putting this into (2), we obtain

\begin{aligned} &\sum_{i=0}^{p-2}\Phi_{i} x (t_{i} ) +\Phi _{p-1} x (t_{p-1} )+\Phi_{p} x (T )\\ &\quad=\sum_{i=0}^{p-1}\Phi_{i} x (t_{i} )+\Phi_{p-1} x (t_{p-1} )+N' (t_{p-1} +0 )x (t_{p-1} )\\ &\qquad{}+n (t_{p-1} +0 )+W (t_{p-1} +0 )\\ &\quad= \sum _{i=0}^{p-1}\Phi_{i} x (t_{i} )+ \bigl[\Phi_{p-1} +N (t_{p-1} +0 ) \bigr]x (t_{p-1} )+n (t_{p-1} +0 )+W (t_{p-1} +0 )=q . \end{aligned}

Hence, we obtain that

\begin{aligned} &\sum_{i=0}^{p-2}\Phi_{i} x (t_{i} )+ [\Phi _{p-1} +N (t_{p-1} +0 ) ]x (t_{p-1} ) \\ &\quad{}+n (t_{p-1} +0 )+W (t_{p-1} +0 )=q , \end{aligned}
(9)

where $$n (t )$$, $$W (t )$$ are the solutions of the differential equations

\begin{aligned} &\dot{n} (t )=N' (t )M (t )N (t ), \\ &\dot{W} (t )=N' (t ) \bigl[M (t )\omega (t )-v (t ) \bigr] \end{aligned}
(10)

on the interval $$(t_{p-1} ,t_{p} )$$ with initial conditions $$n (t_{p} )=0$$, $$W (t_{p} )=0$$.

If we denote

\begin{aligned}& \Phi_{i}^{(1)} =\Phi_{i} ,\quad i=\overline{0,p-2}, \\& \Phi_{p-1}^{(1)} =\Phi_{p-1} +N' (t_{p-1} +0 ), \\& q^{(1)} =q-n (t_{p-1} +0 )v+W (t_{p-1} +0 ), \end{aligned}

then we obtain

$$\sum_{i=0}^{p-1} \Phi_{i}^{(1)} x (t_{i} )=q^{(1)} .$$
(11)

Thus, as a result, we obtain condition (11), where the point $$\{t_{i} \}$$ is smaller by one in comparison to the boundary condition (2). Continuing this procedure k times, we obtain

$$\sum_{i=0}^{p-k} \Phi_{i}^{(k)} x (t_{i} )=q^{(k)} .$$
(12)

Then, according to the same procedure as the one used above, we get

$$\Phi_{p-k}^{(k)} x (t_{p-k} )=N' (t )x (t )+n (t )\gamma+W (t ).$$
(13)

Substituting (13) into (12), at $$t=t_{p-k-1}$$ after some elementary transformations, we obtain

\begin{aligned} &\sum_{i=0}^{p-k-2}\Phi_{i}^{(k)} x (t_{i} )+ \bigl[\Phi_{p-k-1}^{(k)} +N' (t_{p-k-1} +0 ) \bigr]x (t_{p-k-1} ) \\ &\quad=q^{(k)} -n (t_{p-k-1} +0 )\gamma-W (t_{p-k-1} +0 ), \end{aligned}
(14)

where $$n (t )$$, $$W (t )$$ are solutions of equations (9) with conditions $$n (t_{p-k} )=0$$, $$W (t_{p-k} )=0$$ in the interval $$t_{p-k-1}$$, $$t_{p-k}$$.

Then denoting

\begin{aligned} &\Phi_{i}^{(k+1)} =\Phi_{i}^{k} ,\quad i= \overline{0,p-k-2}, \\ &\Phi_{p-k-1}^{(k+1)} =\Phi_{p-k-1}^{k} +N' (t_{p-k-1} +0 ),\\ &q^{(k+1)} =q^{ (k )} -n (t_{p-k-1} +0 )v-W (t_{p-k-1} +0 ), \end{aligned}
(15)

we obtain

$$\sum_{i=0}^{p-k-1}\Phi_{i}^{ (k+1 )} x(t_{i} )=q^{ (k+1 )} .$$

If we continue this procedure $$p-1$$ times, we arrive at

$$\Phi_{0}^{ (p-1 )} x(t_{0} )+ \Phi_{1}^{ (p-1 )} x(t_{1} )=q^{ (p-1 )} .$$
(16)

Finally, applying the above methodology again, we obtain

$$\Phi_{1}^{ (p-1 )} x(t_{1} )=N'(t_{0} +0)x(t_{0} )+n(t_{0} +0) \gamma+W(t_{0} +0).$$
(17)

Here $$n (t )$$ and $$W (t )$$ are solutions of equations (9) with conditions $$n (t_{1} )=0$$, $$W (t_{1} )=0$$ in the interval $$(t_{0} ,t_{1} )$$. Hence, we find that

$$\bigl[\Phi_{0}^{ (p-1 )} +N' (t_{0} +0 ) \bigr]x (t_{1} )+n (t_{0} +0 ) \gamma=q^{ (p-1 )} -W (t_{0} +0 ).$$
(18)

Now, considering the recurrence relation (15), from (18) we have the equation below to determine $$x(t_{0} )$$ and γ

$$\bigl[\Phi_{0} +N' (t_{0} +0 ) \bigr]x (t_{1} )+\sum_{i=0}^{p-1}n (t_{i} +0 )\gamma=q-\sum_{i=0}^{p-1}W (t_{i} +0 ).$$
(19)

Thus, to determine the initial value $$x (t_{0} )$$ and Lagrange multipliers γ, we obtain the system of algebraic equations (7), (19), which can be written in the following matrix form:

\begin{aligned} & \begin{bmatrix} {S (t_{0} )} & {N (t_{0} +0 )+\Phi _{0} ^{\prime} } \\ {\Phi_{0} +N' (t_{0} +0 )}& {\sum_{i=1}^{p-1}n (t_{i} +0 ) } \end{bmatrix} \begin{bmatrix} {x (t_{0} )} \\ {\gamma} \end{bmatrix}= \begin{bmatrix} {-\omega (t_{0} )} \\ {q-\sum_{i=0}^{p-1}W (t_{i} +0 ) } \end{bmatrix}. \end{aligned}
(20)

As can be seen, the main matrix of system (20) is symmetrical.

Solving the system of linear algebraic equations (20), we find $$x_{0} =x(0)$$ and γ. The control $$u(t)$$ is determined by the expression

$$u(t)=C^{-1} (t)G'(t) \bigl(S(t)x(t)+N(t) \gamma+\omega(t)\bigr),$$
(21)

and $$x(t)$$ is a solution of the Cauchy problem

$$\dot{x}(t)=\bigl(F(x)+M(t)S(t)\bigr)x(t)+M(t)N(t)\gamma+M(t) \omega(t)+v(t),$$
(22)

with initial conditions $$x(0)=x_{0}$$.

It should be noted that the coefficients for $$x(t)$$, $$u(t)$$ determined from (21), (22) coincide with the coefficients of the corresponding optimal stabilization problem. This fact significantly simplifies solution of the general optimal control problem (construction of the program trajectories and control, optimal stabilization).

## 3 Statement of the problem (the discrete case)

Let the considered process in $$t\in [0,T ]$$ be described by the equation

$$x(i+1)=\psi(i)x(i)+\Gamma(i)u(i),\quad i=\overline{0,p-1},$$
(23)

with multi-point boundary conditions

$$\sum_{j=0}^{l} \Phi_{j} x(i_{j} )=q,\quad i_{0} =0, i_{l} =p, 0< i_{j} < p, j=\overline {1,l-1} .$$
(24)

It is required to find a control $$u(i)$$ and corresponding trajectory $$E(i)$$ that minimize the functional

$$J=\frac{1}{2} \sum_{i=0}^{p} \bigl[x'(i)Q(i)x(i)+u'(i)C(i)u(i) \bigr] ,$$
(25)

where $$0=t_{0} < t_{1} <\cdots<t_{i} <\cdots<t_{p-1} <t_{p} =T$$, $$\psi(i)$$, $$\Gamma(i)$$ are the matrices of $$n\times n$$ and $$n\times m$$ dimensions, correspondingly, $$E(i)$$ is n-dimensional vector, $$u(i)$$ is m-dimensional vector, $$\Phi_{j}$$ ($$i_{0} =0$$, $$i_{l} =p$$, $$0< i_{j} < p$$, $$j=\overline{1,l-1}$$) are the matrices of dimension $$k\times n$$, q is k-dimensional constant vector.

Constructing the extended functional for problem (23)-(25), we find the corresponding Euler-Lagrange equation

\begin{aligned} &x(i+1)=\psi(i)x(i)-M(i)\lambda(i+1),\quad i=\overline{0,p-1}, \\ &\lambda(i)=Q(i)x(i)+\psi'(i)\lambda(i+1), \\ &\lambda(0)=-\Phi'_{1} \gamma, \\ &\lambda(i_{j} +0)=\lambda(i_{j} -0)-\Phi'_{j} \gamma,\quad j=\overline{1,l-1}, \\ &\lambda(p)=\Phi'_{l} \gamma . \end{aligned}
(26)

Here $$M(i)=\Gamma(i)C^{-1} (i)\Gamma'(i)$$, n-dimensional vector function $$\lambda(i)$$ and k-dimensional constant γ are Lagrange multipliers. We search the unknown discrete function $$\lambda (i)$$ from formula (26) by the following equations:

$$\lambda(i)=S(i)x(i)+N(i)\gamma+\omega(i),\quad i=\overline{0,p},$$
(27)

$$S (i )$$, $$N (i )$$ and $$\omega (i )$$ are discrete unknown functions, which are required to be found. If we put expression (27) into equation (26), after some transformations, we obtain the following system of equations:

\begin{aligned} &S(i)=\psi'(i)S(i+1) \bigl[E-M(i)S(i+1) \bigr]^{-1} \psi(i)+Q(i), \\ &N(i)=\psi'(i) \bigl[E-M(i)S(i+1) \bigr]^{-1} N(i+1),\\ &\omega(i)=\varphi'(i) \bigl[E-M(i)S(i+1) \bigr]^{-1} \omega(i+1). \end{aligned}
(28)

For system (28) we obtain the initial conditions

$$S(p)=0, \qquad N(p)=\Phi'_{l} , \qquad\omega(p)=0$$
(29)

at point $$i=p$$.

Taking $$i=i_{0}$$ in formula (27), we obtain

$$\lambda(i_{0} )=S(i_{0} )x(i_{0} )+N(i_{0} )\gamma+\omega(i_{0} ).$$

Considering the corresponding condition in system (26), we obtain

$$S(i_{0} )x(i_{0} )+N(i_{0} )\gamma+ \omega(i_{0} )=-\Phi'_{1} \gamma,$$

and hence for the unknown variables $$x(i_{0} )$$, γ the equation

$$S(i_{0} )x(i_{0} )+ \bigl[N(i_{0} )\gamma+\Phi'_{1} \bigr]\gamma =-\omega(i_{0})$$
(30)

is obtained. For the unique finding of $$x(i_{0} )$$ and γ, it is necessary to add one more equation to equation (30). To obtain this equation, we use the method given in [5].

If we consider the condition

$$\lambda(i_{j} +0)=\lambda(i_{j} -0)-\Phi'_{j} \gamma,\quad j=\overline{1,l-1}$$

in the expression

\begin{aligned}& \lambda(i_{j} +0)=S(i_{j} +0)x(i_{j} )+N(i_{j} +0)\gamma+\omega(i_{j} +0), \\& \lambda(i_{j} -0)=S(i_{j} -0)x(i_{j} )+N(i_{j} -0)\gamma+\omega(i_{j} -0), \end{aligned}

we obtain

$$S(i_{j} +0)x(i_{j} )+N(i_{j} +0)\gamma+ \omega(i_{j} +0)=S(i_{j} -0)x(i_{j} )+N(i_{j} -0)\gamma+\omega(i_{j} -0)-\Phi'_{j} \gamma.$$

From this we get

\begin{aligned} &S(i_{j} +0)=S(i_{j} -0), \\ &N(i_{j} +0)=\omega(i_{j} -0), \\ &N(i_{j} +0)=N(i_{j} -0)-\Phi'_{j}. \end{aligned}
(31)

Then, according to [5], we obtain

$$\Phi_{l} x(p)=N'(i)x(i)+n(i)\gamma+W(i),\quad i_{l-1} < i< p,$$
(32)

where, for $$i_{l-1} < i< p$$, the unknown discrete functions $$n(i)$$, $$W(i)$$ are defined as solutions of the following system:

\begin{aligned} &n(i)=n(i+1)-N'(i+1) \bigl[E+M(i)S(i+1) \bigr]^{-1} M(i)N(i+1), \\ &W(i)=W(i+1)-N'(i+1) \bigl[E+M(i)S(i+1) \bigr]^{-1} M(i)\omega(i+1). \end{aligned}
(33)

Solutions of this equation satisfying the condition $$i_{l-1} < i< i_{l}$$ are found for all i and must satisfy the initial conditions

\begin{aligned} &n(i_{l} )=n(p)=0, \\ &W(i_{l} )=W(p)=0. \end{aligned}
(34)

If we put $$i=i_{l-1} +0$$ in formula (32), then we have

$$\Phi_{l} x(p)=N'(i_{l-1} +0)x(i_{l-1} )+n(i_{l-1} +0)\gamma+W(i_{l-1} +0).$$

Then putting this expression into (23), we obtain

\begin{aligned}& \sum_{j=0}^{l-2}\Phi_{j} x(i_{j} )+\Phi _{l-1} x(i_{l-1} ) +\Phi_{l} x(i_{l} ) \\& \quad=\sum_{j=0}^{l-2}\Phi_{j} x(i_{j} )+\Phi_{l-1} (x_{i_{l-1} } ) +N'(i_{l-1} +0)x(i_{l-1} )+n(i_{l-1} +0)\gamma+W(i_{l-1} +0) \\& \quad=\sum_{j=0}^{l-2}\Phi_{j} x(i_{j} ) + \bigl[\Phi_{l-1} +N'(i_{l-1} +0) \bigr]x(i_{l-1} )+n(i_{l-1} +0)\gamma+W(i_{l-1} +0)=q. \end{aligned}

Denote

\begin{aligned}& \Phi_{j}^{(1)} =\Phi_{j} ,\quad j=\overline{0,l-2}, \\& \Phi_{l-1}^{(1)} =\Phi_{l-1}+N'(i_{l-1} +0),\\& q^{(1)} =q-n(i_{l-1} +0)\gamma W(i_{l+1} +0), \end{aligned}

then we obtain

$$\sum_{j=0}^{l-1} \Phi_{j}^{(1)} x(i_{j} )=q^{(1)} .$$
(35)

Thus, as a result of the operations, we obtain condition (35) instead of the boundary condition (24), where there is one less point $$\{i_{i} \}$$ than in the boundary condition (24). Continuing this procedure k times, one can get

$$\sum_{j=0}^{l-k} \Phi_{j}^{(k)} x(i_{j} )=q^{(k)} .$$
(36)

Then, according to the used below procedure, instead of (32) we have

$$\Phi_{l-k}^{(k)} x(i_{l-k} )=N'(i)x(i)+n(i) \gamma+W(i),\quad i_{l-k-1} < i< i_{l-k} .$$

Here $$n(i)$$ and $$W(i)$$ are solutions of equations (33) satisfying the condition $$n(i_{l-k} )=0$$, $$W(i_{l-k} )=0$$.

Then denoting again

\begin{aligned} &\Phi_{j}^{(k+1)} =\Phi_{j}^{(k)} ,\quad j=\overline{0,l-k-2}, \\ &\Phi_{l-k-1}^{(k+1)} =\Phi_{l-k-1}^{(k)} +N'(i_{l-k-1} +0), \\ &q^{(k+1)} =q^{(k)} -n(i_{l-k-1} +0)\gamma -W(i_{l-k-1} +0), \end{aligned}
(37)

we obtain

$$\sum_{j=0}^{l-k-1}\Phi_{j}^{(k+1)} x(i_{j} )=q^{(k+1)} .$$

Continuing this procedure $$l-1$$ times, we obtain

$$\Phi_{0}^{(l-1)} x(i_{0} )+ \Phi_{1}^{(l-1)} x(i_{1} )=q^{(l-1)} .$$
(38)

Finally, applying the above procedure once more, we obtain the expression

$$\Phi_{1}^{(l-1)} x(i_{1} )=N'(i)x(i)+n(i)\gamma+W(i),\quad i_{0} < i< i_{1} ,$$
(39)

where $$n(i)$$ and $$W(i)$$ are solutions of equations (33) satisfying the condition $$n(i_{1} )=0$$, $$W(i_{1} )=0$$. Putting $$i=i_{0}$$ in (39) and taking into account (38), we obtain

$$\Phi_{0}^{(l-1)} x(i_{0} )=N'(i_{0} )x(i_{0} )+n(i_{0} )\gamma +W(i_{0} )=q^{(l+1)}$$

or

$$\bigl[N'(i_{0} )+\Phi_{0}^{(l-1)} \bigr]x(i_{0} )+n(i_{0} )\gamma =q^{(l-1)} -W(i_{0} ).$$
(40)

Further, considering the recurrence relation (37) in (40), we obtain the equation to determine $$x(i_{0} )$$ and γ

$$\bigl[N'(i_{0} )+\Phi_{0} \bigr]x(i_{0} )+\sum_{l=1}^{l-1}n (i_{p-k-1} )\gamma=q-\sum_{j=1}^{l-1}W(i_{l-k} )$$
(41)

or

$$\bigl[N'(i_{0} )+\Phi_{0}^{(l-0)} \bigr]x(i_{0} )+n(i_{0} )\gamma =q^{(l-1)} -W(i_{0} ).$$
(42)

If in (40) we take into account the recurrence relations (37), then we obtain

$$\bigl[N'(i_{0} )+\Phi_{0} \bigr]x(i_{0} )+\sum_{l=1}^{l-1}n (i_{p-k-1} )\gamma=q-\sum_{j=1}^{l-1}W(i_{l-k} ) .$$
(43)

Thus, to determine the initial value $$x(i_{0} )$$ and Lagrange multipliers γ, we obtain the system of algebraic equations (30), (41), which can be written in the following matrix form:

$$\begin{bmatrix} {S(i_{0} ) N(i_{0} +0)+\Phi'_{0} } \\ {N'(i_{0} )+\Phi_{0} \sum_{i=0}^{l-1}n(i_{l-k} ) } \end{bmatrix} \begin{bmatrix} {x(i_{0} )} \\ { \gamma} \end{bmatrix}= \begin{bmatrix} {-\omega(i_{0} )} \\ {q-\sum_{i=0}^{l-1}W(i_{l-k} ) } \end{bmatrix}.$$

## 4 The numerical algorithm

For the development of numerical algorithm for the sweep method, we consider the optimal control problem with three-point boundary conditions [6, 7]:

$$\dot{x}(t)=F(t)x(t)+G(t)u(t)+v(t),\quad t\in [0,T ],$$
(44)

with multipoint boundary conditions

$$\Phi_{1} x(0)+\Phi_{2} x(\tau)+ \Phi_{3} x(T)=q,\quad \tau\in(0,T),$$
(45)

where it is required to minimize the functional

$$J=\frac{1}{2} \int_{0}^{T} \bigl[x'(t)Q(t)x(t)+u'(t)C(t)u(t) \bigr]\,dt .$$
(46)

Then, as in the case of multipoint boundary conditions, to determine $$x(0)$$ the following system of linear algebraic equations is obtained:

$$\begin{bmatrix} {S(0)} & {N(0) + \Phi_{1} } \\ {N'(0) + \Phi_{1} } & {n(0) + n(\tau + 0)} \end{bmatrix} \begin{bmatrix} {x(0)} \\ \gamma \end{bmatrix} = \begin{bmatrix} { - \omega(0)} \\ {q - W(0) - W(\tau + 0)} \end{bmatrix},$$
(47)

where $$S(t)$$, $$N(t)$$ and $$\omega(t)$$ are unknown functions. These functions satisfy the following differential equations:

\begin{aligned} &\dot{S}(t)=-F'(t)S(t)-S(t)F(t)+S(t)M(t)S(t)-Q(t), \\ &\dot{N}(t)= \bigl[S(t)M(t)-F'(t) \bigr]N(t), \\ &\dot{\omega}(t)=\bigl[S(t)M(t)-F'(t) \bigr]\omega(t)-S(t)v(t), \end{aligned}
(48)

with initial conditions at the point $$t=T$$

$$S(T) = 0, \qquad N(T) = \Phi'_{3},\qquad\omega(T) = 0,\qquad N(\tau + 0) = N(\tau - 0) - \Phi'_{2}.$$
(49)

Here $$M(t)=G(t)C^{-1} (t)G'(t)$$, and $$n (t)$$, $$W (t)$$ are determined by the following differential equations:

\begin{aligned} &\dot{n}(t)=N'(t)M(t)N(t), \\ &\dot {W}(t)=N'(t)\bigl[M(t)W(t)-v(t)\bigr] \end{aligned}
(50)

with initial conditions $$n(T)=0$$, $$W(T)=0$$ in the interval $$\tau+0< t< T$$, and with initial conditions $$n(\tau-0)=0$$, $$W(\tau-0)=0$$ in the interval $$0< t<\tau-0$$.

Solving the system of linear algebraic equations (47), we find $$x_{0} =x(0)$$ and γ. Then the control $$u(t)$$ is determined as follows:

$$u(t)=C^{-1} (t)G'(t) \bigl(S(t)x(t)+N(t) \gamma+\omega(t)\bigr),$$
(51)

and $$x(t)$$ as a solution of the Cauchy problem

$$\dot{x}(t)= \bigl[F(t)+M(t)S(t) \bigr]x(t)+M(t)N(t)\gamma+M(t) \omega(t)+v(t)$$
(52)

with initial condition $$x(0)=x_{0}$$.

Considering the above formulae, the following algorithm may be offered for solving problem (44)-(46):

1. (1)

$$F(x)$$, $$G(t)$$, $$v(t)$$, $$\Phi_{1}$$, $$\Phi_{2}$$, $$\Phi_{3}$$, q, $$Q(t)$$, $$C(t)$$ are formed.

2. (2)

The functions $$S(t)$$, $$N(t)$$ and $$\omega(t)$$ are determined by solving problems (45)-(46).

3. (3)

The solutions of equation (47) - the functions $$n(t)$$ and $$W(t)$$ - are determined.

4. (4)

$$x_{0} =x(0)$$ and γ are determined by solving the system of linear algebraic equations (47).

5. (5)

$$u(t)$$ is determined by formula (51).

6. (6)

The solution $$x(t)$$ is obtained from equation (51).

This algorithm implies that to determine $$x(t)$$ one should solve the Riccati equation and the system of differential equations. To demonstrate the performance of this algorithm, we use Runge-Kutta method.

First of all we reduce the initial condition at the point $$t=T$$ to the initial condition at the point $$t=0$$. We illustrate this transformation by the example of the first equation in (48). Let

\begin{aligned} &\dot{S}(t)=-F'(t)S(t)-S(t)F(t)+S(t)M(t)S(t)-Q(t),\\ &S(t_{1} )=S^{0} . \end{aligned}
(53)

Introducing $$\tau=t_{1} -t$$ and denoting $$S(t)=S(t_{1} -\tau)=\bar {S}(\tau)$$, from (53) we obtain

\begin{aligned}& \dot{\bar{S}}(\tau)=-F'\bar{S}(\tau)-\bar{S}(\tau )F+\bar{S}(\tau)MS(\tau)-Q, \\& \bar{S}(0)=S^{0} ,\quad 0\le\tau\le t_{1} . \end{aligned}

In analogous way we can transform the other equations of (48) and (50).

We consider the case when $$Q(t)=0$$ and $$v(t)=0$$. From equations (48) we obtain $$S(t)\equiv0$$, $$\omega(t)\equiv0$$, the functions $$\bar{N}(t)$$, $$\bar{n}(t)$$ and $$\bar{W}(t)$$ being solutions of the differential equations

\begin{aligned} &\dot{\bar{N}}(t)=-F'(t)\bar{N}(t), \\ &\dot{\bar{n}}(t)=\bar{N}'(t)M(t)\bar{N}(t), \\ &\dot{\bar{W}}(t)=\bar{N}'(t)\bigl[M(t)\bar{W}(t) \bigr] \end{aligned}
(54)

with initial conditions $$\bar{N}(0)=\Phi'_{3}$$, $$\bar {n}(0)=0$$, $$\bar{W}(0)=0$$ for the interval $$0< t<\tau-0$$ and $$\bar {n}(\tau+0)=0$$, $$\bar{W}(\tau+0)=0$$ for the interval $$\tau +0< t< T$$. Note that at $$\tau=\frac{T}{2}$$ the last condition (49) implies

$$\bar{N}(\tau-0)=\bar{N}(\tau+0)-\Phi'_{2}.$$
(55)

The system of differential equations (51) is more convenient for application of Runge-Kutta method:

\begin{aligned}& \bar{N}(t_{i+1} )=N(t_{i} )+\frac{h}{6} (k_{1} +2k_{2} +2k_{3} +k_{4} ), \\& k_{1} =-F'\bar{N}(t_{i} ), \\& k_{2} =-F' \biggl(\bar{N}(t_{i} )+k_{1} \cdot\frac{h}{2} \biggr), \\& k_{3} =-F' \biggl(\bar{N}(t_{i} )+k_{2} \cdot\frac{h}{2} \biggr), \\& k_{4} =-F' \bigl(\bar{N}(t_{i} )+k_{3} \cdot h \bigr),\quad h=\frac{t_{i+1} -t_{i} }{h} . \end{aligned}

Note that condition (55) somehow complicates the application of Runge-Kutta method in solving equation (54). To overcome the difficulties that occurred, we divide the interval $$[0,T ]$$ into n equal parts so that the point $$t=\tau$$ would coincide with one of the nodal points $$t_{i}$$. Then, considering the initial condition $$\bar{N}(0)=\Phi'_{3}$$, we find the solution on the interval $$(0,\tau+0)$$, and using this solution as the initial conditions we obtain the next solution on the entire interval $$(0,T)$$. To find the functions $$\bar{n}(t)$$ and $$\bar{W}(t)$$, we also apply Runge-Kutta method, but in this case on each interval $$(0,\tau)$$ and $$(\tau,T)$$ the corresponding differential equations are solved independently.

For $$\bar{n}(t)$$, considering the notation $$R(i)=N'(i)MN(i)$$, we obtain

\begin{aligned}& k_{1} =N'(t_{i} )M\bar{W}(i),\\& k_{2} =R(i) \biggl(E+k_{1} \cdot\frac{h}{2} \biggr). \end{aligned}

Further, for $$\bar{W}(t)$$, we denote $$R(i)=N'(i)MN(i)$$ to find

\begin{aligned}& k_{1} =N'(t_{i} )M\bar{W}(i),\\& k_{2} =P(i) \biggl(E+k_{1} \cdot\frac{h}{2} \biggr),\\& k_{3} =P(i) \biggl(E+k_{2} \cdot\frac{h}{2} \biggr),\\& k_{4} =P(i) (E+hk_{3} ),\\& \bar{W}(i+1)=\bar{W}(i)+\frac{h}{6} (k_{1} +2k_{2} +2k_{3} +k_{4} ). \end{aligned}

Thus, using Runge-Kutta method for $$\bar{n}$$, $$\bar{W}$$, we obtain the corresponding solution. By solving the system of linear algebraic equations (47) we find the initial condition $$x(0)$$ and Lagrange multiplier γ. At $$S(t)\equiv0$$ the value of $$x(t_{i} )$$ is determined from the system of differential equations (51), (52) by Runge-Kutta method.

## 5 Conclusion

In this paper, we explore sweep algorithm for solving optimal control problem with multi-point boundary conditions. Numerical examples demonstrate the performance of the proposed algorithm. The results can be applied to other examples [813].

## References

1. Abramov, AA: On the transfer of boundary conditions for systems of ordinary linear differential equations (a variant of the dispersive method). USSR Comput. Math. Math. Phys. 1(3), 617-622 (1962)

2. Mutallimov, MM, Zulfugarova, RT: Sweep method for solving discrete optimal control problems with multipoint boundary conditions. Rep. Nat. Acad. Sci. Azerb. LXV(4), 36-41 (2009) (in Russian)

3. Aliev, FA: Methods of Solution for the Application Problems of Optimization of the Dynamic Systems. Elm, Baku (1989), 317 p.

4. Bryson, A, Ho, YC: Applied Optimal Control Theory (1972) (in Russian), 543 p.

5. Polak, E: Computational Methods in Optimization: A Unified Approach. Academic Press, New York (1971)

6. Aliev, FA, Abbasov, AN, Mutallimov, MM: Algorithm for solution of the problem of optimization of the energy expenses at the exploitation of chinks by subsurface-pump installations. Appl. Comput. Math. 3(1), 2-9 (2004)

7. Aliev, FA, Zulfugarova, RT, Mutallimov, MM: Sweep algorithm for solving discrete optimal control problems with three-point boundary conditions. J. Autom. Inf. Sci. 40(7), 48-58 (2008)

8. Majidzadeh, K, Mutallimov, MM, Niftiyev, AA: The problem of optimizing the torsional rigidity of a prismatic body about a cross section. J. Appl. Math. Mech. 76(4), 482-485 (2012)

9. Mutallimov, MM, Askerov, IM, Ismailov, NA, Rajabov, MF: An asymptotical method to construction a digital optimal regime for the gaslift process. Appl. Comput. Math. 9(1), 77-84 (2010)

10. Aliev, FA, Mutallimov, MM, Askerov, IM, Ragimov, IS: Asymptotic method of solution for a problem of construction of optimal gas-lift process modes. Math. Probl. Eng. 2010, Article ID 191053 (2010)

11. Mardanov, MJ, Sharifov, YA: Pontryagin’s maximum principle for the optimal control problem with multipoint boundary conditions. Abstr. Appl. Anal. 2015, Article ID 428042 (2015)

12. Gabasova, OR: On optimal control of linear hybrid systems with terminal constraints. Appl. Comput. Math. 13(2), 194-205 (2014)

13. Agamalieva, LF, Aliev, FA, Gasimov, YS, Veliyeva, NI: High accuracy algorithms to solution of the discrete synthesis problems with measurement errors. Ciênc. Téc. Vitiviníc. 30(5), 29-36 (2015)

## Acknowledgements

The authors are grateful to prof. FA Aliev and prof. YS Gasimov for their valuable advice. The authors also are grateful to the anonymous referees for their constructive comments and helpful suggestions to improve this paper greatly.

## Author information

Authors

### Corresponding author

Correspondence to Rena T Zulfugarova.

### Competing interests

The authors declare that they have no competing interests.

### Authors’ contributions

All the authors participated in obtaining the main results of the paper. All authors read and approved the final manuscript.

## Rights and permissions

Reprints and permissions

Mutallimov, M., Zulfugarova, R.T. & Amirova, L.I. Sweep algorithm for solving optimal control problem with multi-point boundary conditions. Adv Differ Equ 2015, 233 (2015). https://doi.org/10.1186/s13662-015-0569-5