1 Introduction

The process of opinion formation in a social network (a network of social actors connected by social ties) is rapidly attracting the attention of scholars in many disciplines, ranging from sociology to mathematics [1,2,3,4,5,6]. There are two different approaches in mathematical modeling of social dynamics. The first is macroscopic and applies tools from continuum mechanics and partial differential equations. The other is microscopic and treats social actors (agents, individuals) in the group as separate objects interacting with each other. In this work, we use the second approach and consider an agent-based model with real-valued opinions. Namely, our model consists in a nonlinear system of fractional-order differential equations. Fractional derivatives are non-local operators [7] and therefore are proper for modeling systems with long range interactions in space and/or time (memory), and processes with many scales of space and/or time involved [8,9,10]. We thus argue that fractional-order systems can better describe memory and hereditary properties of the process of opinion formation than integer-order ones.

One of the first agent-based models of opinion formation was the French–DeGroot model, proposed in 1974 [11]. Since then, the most important characteristic of such models has been the emergence of a consensus, where a group of agents agree upon certain quantities of interest such as position, price, etc. Roughly speaking, the consensus problem of agent-based models can be treated as a special case of the asymptotic stability problem of dynamical systems. Although consensus is a behavior, that we would expect in opinion formation models, there are situations when the opinions do not reach consensus and we observe polarization of opinions or chaos [12,13,14]. In such situations, one possible way to steer all agents to reach a consensus consists in introducing a (virtual) leader to the system and possibly controlling the leader [15,16,17,18]. The (virtual) leader is a special agent, whose opinion is independent of all the other agents’ opinions. This approach has roots in real-world phenomena such as the relations between a sheepdog and sheep [19], or the influence of mass media on opinions of members of society. In addition, controlling the system through the leader is justified in practice, e.g., crowd evacuation in case of panic situations [20], or designing reference trajectories for a master robot to guide slave robots [21].

In this paper, we study a nonlinear fractional leader–follower model of opinion formation. The contribution of the paper is twofold. First, some sufficient conditions are established to ensure that the opinions of all agents globally asymptotically approach the opinion of the leader. Second, we address the problem of designing optimal control strategies for the leader so that the followers tend to consensus in the most efficient way. In other words, external control is applied to the leader in a manner that minimizes disagreements among all agents and the amount of interventions.

The rest of the paper is organized as follows. In Sect. 2, some preliminaries about fractional operators are given. The fractional opinion formation model with a leader is discussed in Sect. 3. Section 4 presents the leader–follower optimal control problem. The necessary and sufficient optimality conditions for this problem are given. In Sect. 4.1, we discuss a variational integrator scheme for the Hamiltonian system. This numerical method guarantees preservation of the variational structure of the underlying system at the discrete level [22,23,24,25,26,27]. Numerical examples, presented in Sect. 5, demonstrate the effectiveness of the proposed control strategy. Finally, conclusions are given in Sect. 6.

2 Preliminaries

In this section, following [28], some basic concepts about fractional operators are introduced. Let \(f:[a,b]\rightarrow \mathbb {R}\) and \(\alpha \in \mathbb {R}_{+}\). We define the left Riemann–Liouville fractional integral of order \(\alpha \) by

$$\begin{aligned} I^{\alpha }_{a+}[f](t):=\frac{1}{\varGamma (\alpha )}\int \limits _a^t(t-\tau )^{\alpha -1}f(\tau )\mathrm{d}\tau ,~~t>a, \end{aligned}$$

and the right Riemann–Liouville fractional integral of order \(\alpha \) by

$$\begin{aligned} I^{\alpha }_{b-}[f](t):=\frac{1}{\varGamma (\alpha )}\int \limits _t^b(\tau -t)^{\alpha -1}f(\tau )\mathrm{d}\tau ,~~t<b, \end{aligned}$$

provided that the right-hand side terms are well defined. Fractional derivatives can be defined using the definition of fractional integrals. To this end, suppose that \(\alpha \in ]0,1[\). Then, the left and right Riemann–Liouville fractional derivatives (RLFD) of function f are given by

$$\begin{aligned} D^{\alpha }_{a+}[f](t):=\left( \frac{\mathrm{d}}{\mathrm{d}t}\circ I^{1-\alpha }_{a+}\right) [f](t),~~t>a, \end{aligned}$$

and

$$\begin{aligned} D^{\alpha }_{b-}[f](t):=-\left( \frac{\mathrm{d}}{\mathrm{d}t}\circ I^{1-\alpha }_{b-}\right) [f](t),~~t<b, \end{aligned}$$

respectively, provided that the right-hand side terms are well defined. Let us note that the RLFD of a constant are not zero: for \(A\in \mathbb {R}\setminus \{0\}\) one has \(D^{\alpha }_{a+}[A](t)=\frac{A}{\varGamma (1-\alpha )}\cdot \frac{1}{(t-a)^{\alpha }}\) and \(D^{\alpha }_{b-}[A](t)=\frac{A}{\varGamma (1-\alpha )}\cdot \frac{1}{(b-t)^{\alpha }}\). Moreover, for a regular function f, they are singular: \(\lim \nolimits _{t\rightarrow a}D^{\alpha }_{a+}[f](t)=\infty \), unless \(f(a)=0\), and \(\lim \nolimits _{t\rightarrow b}D^{\alpha }_{b-}[f](t)=-\infty \), unless \(f(b)=0\). These facts motivated the introduction of Caputo fractional derivatives. The left and right Caputo fractional derivatives (CFD) are defined as

$$\begin{aligned} {^{c}}D^{\alpha }_{a+}[f](t):=D^{\alpha }_{a+}[f(\tau )-f(a)](t),~~t>a, \end{aligned}$$
(1)

and

$$\begin{aligned} {^{c}}D^{\alpha }_{b-}[f](t):=D^{\alpha }_{b-}[f(\tau )-f(b)](t),~~t<b, \end{aligned}$$
(2)

respectively, provided that the right-hand side terms are well defined. Note that, for absolutely continuous functions, we have

$$\begin{aligned} {^{c}}D^{\alpha }_{a+}[f](t)= & {} \left( I^{1-\alpha }_{a+}\circ \frac{\mathrm{d}}{\mathrm{d}t}\right) [f](t),~~t>a\\ {^{c}}D^{\alpha }_{b-}[f](t)= & {} -\left( I^{1-\alpha }_{b-}\circ \frac{\mathrm{d}}{\mathrm{d}t}\right) [f](t),~~t<b, \end{aligned}$$

and, as expected, \({^{c}}D^{\alpha }_{a+}[A](t)=0\), \({^{c}}D^{\alpha }_{b-}[A](t)=0\), \(\lim \nolimits _{t\rightarrow a}{^{c}}D^{\alpha }_{a+}[f](t)=0\), and \(\lim \nolimits _{t\rightarrow b}{^{c}}D^{\alpha }_{b-}[f](t)=0\). Because of the non-local character of RLFD and CFD fractional differential equations often have to be solved numerically. In this paper, we use a method that is based on the Grünwald–Letnikov approximations of Riemann–Liouville and Caputo derivatives. The left and right Grünwald–Letnikov fractional derivatives (GLFD) of a function f, of order \(\alpha \), are given by

$$\begin{aligned} {^{GL}}D^{\alpha }_{a+}[f](t):=\lim \limits _{h\rightarrow 0^+}\frac{1}{h^\alpha }\sum \limits _{r=0}^\infty (w_r^\alpha )f(t-rh) \end{aligned}$$

and

$$\begin{aligned} {^{GL}}D^{\alpha }_{b-}[f](t):=\lim \limits _{h\rightarrow 0^+}\frac{1}{h^\alpha }\sum \limits _{r=0}^\infty (w_r^\alpha )f(t+rh), \end{aligned}$$

respectively. Here \((w_k^\alpha ):=(-1)^k\left( {\begin{array}{c}\alpha \\ k\end{array}}\right) \). It is a well known fact that the truncated GLFD are first-order approximations of RLFD (see, e.g., [7]). Precisely, let \(\mathbb {T}=\left\{ t_k\right\} _{k=0,\dots ,M}=\left\{ a+kh\right\} _{k=0,\dots ,M}\) be the usual regular partition of the interval [ab] with \(M\ge 2\) and \(h=(b-a)/M\). Then, we have

$$\begin{aligned} D^{\alpha }_{a+}[f](t_k)\approx & {} \frac{1}{h^\alpha }\sum \limits _{r=0}^k(w_r^\alpha )f(t_{k-r})=:\varDelta ^{\alpha }_{a+}[f](t_k),~~k=1,\dots ,M,\\ D^{\alpha }_{b-}[f](t_k)\approx & {} \frac{1}{h^\alpha }\sum \limits _{r=0}^{M-k}(w_r^\alpha )f(t_{k+r})=:\varDelta ^{\alpha }_{b-}[f](t_k),~~k=0,\dots ,M-1. \end{aligned}$$

Using (1)–(2), we immediately deduce the following decomposition sum for the CFD:

$$\begin{aligned} {^{c}}D^{\alpha }_{a+}[f](t_k)\approx \frac{1}{h^\alpha }\sum \limits _{r=0}^k(w_r^\alpha )f(t_{k-r})-\frac{f(a)}{\varGamma (1-\alpha )}(t_k-a)^{-\alpha }=:{^{c}}\varDelta ^{\alpha }_{a+}[f](t_k), \end{aligned}$$
(3)

\(k=1,\dots ,M,\)

$$\begin{aligned} {^{c}}D^{\alpha }_{b-}[f](t_k)\approx \frac{1}{h^\alpha }\sum \limits _{r=0}^{M-k}(w_r^\alpha )f(t_{k+r}) -\frac{f(b)}{\varGamma (1-\alpha )}(b-t_k)^{-\alpha }=:{^{c}}\varDelta ^{\alpha }_{b-}[f](t_k), \end{aligned}$$
(4)

\(k=0,\dots ,M-1\).

3 Fractional Opinion Formation Model

Let us consider the continuous-time opinion formation model of \(N\ge 2\) interacting agents, whose opinions henceforth are denoted by \(x_1,\dots ,x_N\):

$$\begin{aligned} {}^{\mathrm{c}} D^{\alpha }_{0+}[x_i](t)=\sum \limits _{j=1}^N a_{ij}(f_j(x_j(t))-f_i(x_i(t))),~~i=1,\dots ,N, \end{aligned}$$
(5)

with the given initial conditions \(x_i(0)=\xi _i\in \mathbb {R}\), for \(i=1,\dots ,N\). The weights \(a_{ij}\in \mathbb {R}\) quantify the way that the agents influence each other, i.e., \(a_{ij}>0\) if agent j is able to influence the opinion of agent i and \(a_{ij}=0\) otherwise, for \(i,j,=1,\dots ,N\); \(\alpha \in ]0,1[\) denotes the significance of the memory in the interaction mechanism. Moreover, we assume that functions \(f_j\), \(j=1,\dots ,N,\) are continuous and satisfy the Lipschitz condition on \(\mathbb {R}\) with Lipschitz constants \(l_j>0\), i.e., \(|f_j(x)-f_j(y)|\le l_j|x-y|\) for every \(x,y\in \mathbb {R}\) and \(j=1,\dots ,N\). The crucial question regarding model (5) is whether the opinions converge to the same unique opinion, which means consensus.

Definition 3.1

We call consensus a configuration in which the opinions of all agents are equal, i.e., \(x^* \in \mathbb {R}^N\) such that \(x^*_1=x^*_2=\ldots =x^*_N\). We say that a solution \(x(t)=(x_{1}(t),\ldots ,x_{N}(t))^T\) of system (5) tends to consensus if there exists a consensus configuration \(x^* \in \mathbb {R}^N\) such that \(\lim \nolimits _{t\rightarrow \infty }x_i(t)=x^*_i\) for every \(i=1,\dots ,N\).

One possible way to steer all agents to reach a consensus is by introducing a virtual leader (e.g., mass media) to the system. The virtual leader is a special agent whose opinion, denoted by \(x_0\), is independent of all the other agents’ opinions. Let us consider the following model with leadership:

$$\begin{aligned} {}^{\mathrm{c}} D^{\alpha }_{0+}[x_i](t)= & {} \sum \limits _{j=1}^N a_{ij}(f_j(x_j(t))-f_i(x_i(t)))+c_i(x_0(t)-x_i(t)), \end{aligned}$$
(6)
$$\begin{aligned} {}^{\mathrm{c}} D^{\alpha }_{0+}[x_0](t)= & {} 0 \end{aligned}$$
(7)

for \(i=1,\dots ,N\), and given initial conditions \(x_i(0)=\xi _i\in \mathbb {R}\), for \(i=0,\dots ,N\). The second term in dynamics (6) describes the leader’s influence, i.e., \(c_i>0\) if the ith agent’s opinion is influenced by the leader and \(c_{i}=0\) otherwise. Equivalently, system (6) can be written as

$$\begin{aligned} {}^{\mathrm{c}} D^{\alpha }_{0+}[x_i](t)=\sum \limits _{j=1}^N b_{ij}f_j(x_j(t))+c_i(x_0(t)-x_i(t)), ~~i=1,\dots ,N, \end{aligned}$$
(8)

where \(b_{ij}=a_{ij}\) for \(i\ne j\) and \(b_{ij}=-\sum \nolimits _{i\ne j}a_{ij}\) for \(i=j\).

Theorem 3.1

Suppose that \(f_i(x_i)=x_i\) and \(c_{i}>0\) for every \(i=1,\dots ,N\). Then, a solution of system (8) tends to consensus \(x^*=(\xi _0,\ldots ,\xi _0)^T\in \mathbb {R}^N\).

Proof

Let us first observe that from (7) we have \(x_0(t)=\xi _0\), and with change of variables \(y_i=x_i-\xi _0\), \(i=1,\dots ,N\), system (8) can be written in the matrix form:

$$\begin{aligned} {}^{\mathrm{c}} D^{\alpha }_{0+}[y](t)=(B-C)y(t), \end{aligned}$$
(9)

where \(B=[b_{ij}]_{N\times N}\) and \(C= {\hbox {diag}} \{c_1,\ldots ,c_N\}\). Based on the Gersgorin theorem [29], all the eigenvalues of matrix \(B-C\) are located in the union of N disks: \(\bigcup _{i=1}^{N}\{z\in \mathbb {R}^2:~~|z+\sum \nolimits _{i\ne j}a_{ij}+c_i|\le \sum \nolimits _{i\ne j}a_{ij}\}.\) Since \(c_{i}>0\) for every \(i=1,\dots ,N\), matrix \(B-C\) has all eigenvalues with negative real parts. Therefore, by Theorem 1 in [30], system (9) is asymptotically stable, which means that \(\lim \nolimits _{t\rightarrow \infty }\Vert y(t)\Vert =0\) for a solution to (9) with any initial conditions. It follows that \(\lim \nolimits _{t\rightarrow \infty }x_i(t)=\xi _0\) for every \(i=1,\dots ,N\). \(\square \)

Theorem 3.2

Suppose that \(f_i(\xi _0)=0\), \(c_i>0\) and \(c_i-\sum \nolimits _{j=1}^N|b_{ji}|l_i>0\) for every \(i=1,\dots ,N\). Then, a solution of system (8) tends to consensus \(x^*=(\xi _0,\ldots ,\xi _0)^T\in \mathbb {R}^N\).

Proof

By (7), we get \(x_0(t)=\xi _0\). Let us introduce the new variables \(y_i=x_i-\xi _0\) and define functions \(g_i(y_i):=f_i(y_i+\xi _0)\), for \(i=1,\dots ,N\). Then, system (8) takes the following form

$$\begin{aligned} {}^{\mathrm{c}} D^{\alpha }_{0+}[y_i](t)=\sum \limits _{j=1}^N b_{ij}g_j(y_j(t))-c_iy_i(t). \end{aligned}$$
(10)

We have

$$\begin{aligned} \forall y,\bar{y}\in \mathbb {R}\quad |g_i(y_i)-g_i(\bar{y}_i)|\le |f_i(y_i+\xi _0)-f_i(\bar{y}_i+\xi _0)|\le l_i |y_i-\bar{y}_i|, \end{aligned}$$

\(c_i>0\) and \(c_i-\sum \nolimits _{j=1}^N|b_{ji}|l_i>0\) for every \(i=1,\dots ,N\). Hence, Theorem 3 in [31] implies that a unique equilibrium point \(y^*\) of system (10) exists, and \(\lim \nolimits _{t\rightarrow \infty }\left\| y(t)-y^*\right\| =0\) for any solution of (10). Since \(g_j(0)=f_j(\xi _0)=0\), it follows that \(y^*=(0,\ldots ,0)^T\) and consequently \(\lim \nolimits _{t\rightarrow \infty }x_i(t)=\xi _0\) for every \(i=1,\dots ,N\). \(\square \)

4 Optimal Leader–Follower Control

In this section, we are interested in situations where the assumptions of Theorem 3.2 are not satisfied. In such a case, one should apply different approaches to steer agents to reach a consensus. We propose introducing external control strategies to the model via the leader, i.e., we consider the following system

$$\begin{aligned}&{}^{\mathrm{c}} D^{\alpha }_{0+}[x_0](t)=u(t),\nonumber \\&{}^{\mathrm{c}} D^{\alpha }_{0+}[x_i](t)=\sum \limits _{j=1}^N b_{ij}f_j(t,x_j(t))+c_i(x_0(t)-x_i(t))+h_i(t),\nonumber \\&x_i(0)=\xi _i\in \mathbb {R},\qquad i=0,1,\dots ,N, \end{aligned}$$
(11)

where \(\alpha \in ]0,1[\), \(b_{ij}\in \mathbb {R}\), \(c_i\ge 0\) for \(i,j,=1,\dots ,N\) and \(u\in L^\infty ([0,T];\mathbb {R})\). Additionally, we generalize system (6) by introducing noise functions \(h_i\in L^\infty ([0,T];\mathbb {R})\), \(i=1,\dots ,N\) to (11) and allowing functions \(f_j\) to depend on t. Precisely, functions \(f_j\), \(j=1,\dots ,N\) are of class \(C^1\) with respect to \(x_j\) and satisfy the Lipschitz condition: for every \(x,y\in \mathbb {R}\) and every \(t\in [0,T]\), \( |f_j(t,x)-f_j(t,y)|\le l_j|x-y|.\) In order to use the least amount of intervention, we seek to minimize the following cost functional:

$$\begin{aligned} \mathcal {J}(x,u) =\int \limits _0^T\Biggl [ \frac{1}{2N^2}\sum \limits _{i,j=1}^N(x_i(t)-x_j(t))^2 +\frac{1}{2}\sum \limits _{i=1}^N(x_0(t)-x_i(t))^2 +\frac{\nu }{2}u^2(t)\Biggr ]\;\mathrm{d}t, \end{aligned}$$
(12)

where \(\nu >0\) denotes the weight constant (in this way, the level of control will be penalized). For simplicity, for the rest of the paper, we use \(x=(x_0,x_1,\ldots ,x_N)^T\in \mathbb {R}^{N+1}\).

Remark 4.1

Let \(\Vert x \Vert _{1}=\sum _{i=0}^{N}|x_i|\) and consider the map \(\tilde{F}:\mathbb {R}^{N+1}\rightarrow \mathbb {R}^{N+1}\), \(\tilde{F}(x):=\left[ \tilde{F}_0(x),\ldots ,\tilde{F}_N(x)\right] ^T\), where

$$\begin{aligned} \tilde{F}_0(x):=u(t),~~\tilde{F}_i(x):=-c_ix_i+\sum \limits _{j=1}^Nb_{ij}f_j(t,x_j)+c_ix_0+h_i(t),~~i=1,\dots , N. \end{aligned}$$

Note that,

$$\begin{aligned} |\tilde{F}_i(x)-\tilde{F}_i(\bar{x})|= & {} |-c_i(x_i-\bar{x}_i+\sum \limits _{j=1}^Nb_{ij}(f_j(t,x_j)-f_j(t,\bar{x}_j))|\\&\le c_i|x_i-\bar{x}_i|+\sum \limits _{j=1}^N|b_{ij}|l_j|x_j-\bar{x}_j|,~~x,\bar{x}\in \mathbb {R}^N,~~i=1,\dots ,N. \end{aligned}$$

Moreover, if \(L_i:=\max \left\{ c_i+|b_{ii}|l_i,\max \nolimits _{j=1,\dots ,N, j\ne i}\left\{ |b_{ij}|l_i\right\} \right\} \), \(i=1,\ldots ,N,\) then

$$\begin{aligned} \sum \limits _{i=0}^N|\tilde{F}_i(x)-\tilde{F}_i(\bar{x})|\le \sum \limits _{i=1}^NL_i\sum \limits _{j=1}^N|x_j-\bar{x}_j| \end{aligned}$$

and for \(L=\max \nolimits _{i=1,\dots ,N}\left\{ L_i\right\} \), we have

$$\begin{aligned} \left\| \tilde{F}(x)-\tilde{F}(x)\right\| _{1} =\sum \limits _{i=0}^N|\tilde{F}_i(x)-\tilde{F}_i(\bar{x})|\le LN\sum \limits _{j=0}^N|x_j-\bar{x}_j| =LN\left\| x-\bar{x}\right\| _{1}. \end{aligned}$$

Therefore, \(\tilde{F}\) is globally Lipschitz and consequently, by Theorem C.3 in [25] (see also [24]), for a given control function \(u\in L^\infty ([0,T];\mathbb {R})\) and a given initial condition \(x(0)=\xi \in \mathbb {R}^{N+1}\), a unique weak solution \(x\in C([0,T];\mathbb {R}^{N+1})\) of system (11) exists.

When solving optimal control problems, usually, the first step is to apply the Pontryagin Maximum Principle. Let us define functions \(F:[0,T]\times \mathbb {R}^{N+1}\times \mathbb {R}\rightarrow \mathbb {R}^{N+1}\), by

$$\begin{aligned} F(t,x(t),u(t)):=\left[ \begin{array}{l} u(t)\\ \sum \limits _{j= 1}^N b_{ij}f_j(t,x_j(t))+c_i(x_0(t)-x_i(t))+h_i(t) \end{array}\right] _{i=1,\dots ,N}, \end{aligned}$$

\(G:[0,T]\times \mathbb {R}^{N+1}\times \mathbb {R}\rightarrow \mathbb {R}\), by

$$\begin{aligned} G(t,x(t),u(t)):=\frac{1}{2N^2}\sum \limits _{i,j=1}^N(x_i(t)-x_j(t))^2 +\frac{1}{2}\sum \limits _{i=1}^N(x_0(t)-x_i(t))^2 +\frac{\nu }{2}u^2(t) \end{aligned}$$

and the Hamiltonian \(H:[0,T]\times \mathbb {R}^{N+1}\times \mathbb {R}\times \mathbb {R}^{N+1}\rightarrow \mathbb {R}\), by \(H(t,x,u,\lambda ):=G(t,x,u)+\lambda F(t,x,u).\) Based on the results proved in [23,24,25] (see also [32, 33]), we state the necessary optimality conditions for problem (11)–(12).

Theorem 4.1

If the trajectory \(x^*\), defined on [0, T] and associated with a control \(u^*\in L^\infty ([0,T];\mathbb {R})\), is a solution to problem (11)–(12), then there exists a function \(\lambda \in H^{\alpha }([0,T];\mathbb {R}^{N+1})\) such that:

  1. (i)

    \(x^*\) and \(\lambda \) are weak solutions to the Hamiltonian system

    $$\begin{aligned}&{}^{\mathrm{c}} D^{\alpha }_{0+}[x](t)=\displaystyle \frac{\partial H}{\partial \lambda }(t,x(t),u^*(t),\lambda (t)),\nonumber \\&{}^{\mathrm{c}} D^{\alpha }_{T-}[\lambda ](t)=\displaystyle \frac{\partial H}{\partial x}(t,x(t),u^*(t),\lambda (t)), \quad t\in [0,T]; \end{aligned}$$
    (13)
  2. (ii)

    \(\lambda (T)=0\);

  3. (iii)

    the stationary condition \(\lambda _0(t)=-\nu u^*(t)\) holds for almost every \(t\in [0,T]\).

Under additional assumptions, we can prove sufficient optimality conditions for problem (11)–(12).

Theorem 4.2

Assume that functions \(f_j\) are convex in \(x_j\) for all \(j=1,\ldots ,N\) and \(\lambda (t)\ge 0\) for all \(t\in [0,T]\) or \(f_j\) are linear in \(x_j\) for all \(j=1,\ldots ,N\). If \(x^*\), \(u^*\) and \(\lambda \) satisfy conditions (i)–(iii) of Theorem 4.1, then \(x^*\) associated with a control \(u^*\) is a solution to problem (11)–(12).

Proof

It follows easily from Theorem 10.3 in [34]. \(\square \)

4.1 Variational Integrator for the Leader–Follower Control Problem

As mentioned in Sect. 2, the non-local character of fractional derivatives causes difficulties in finding the exact solutions to most non-integer-order differential equations. This concerns, in particular, system (13). Moreover, using conditions (i)–(iii) of Theorem 4.1, we obtain a boundary value problem for \((x,\lambda )\) involving both left and right CFD. Therefore, in this section, we propose a numerical scheme for fractional optimal control problem (11)–(12). We use the idea of variational integrators, which consists of two steps: first, we define a discrete version of problem (11)–(12); second, we apply the corresponding discrete Weak Pontryagin’s Maximum Principle to it. As a consequence, this numerical method will preserve the variational structure of system (13) at the discrete level. Discretization of problem (11)–(12) is based on approximation (3) of the Caputo derivative. To this end, let \(\mathbb {T}=\{t_k\}_{k=0,\dots ,M}=\{kh\}_{k=0,\dots ,M}\) be the usual regular partition of the interval [0, T], with \(M\ge 2\) and \(h=\frac{T}{M}\) , such that \(2h^\alpha NL<1\), where L is defined as in Remark 4.1. We consider the discrete analogue of problem (11)–(12) given by the system

$$\begin{aligned}&{^{c}}\varDelta ^{\alpha }_{0+}[x_0](t_k)=u(t_k),\nonumber \\&{^{c}}\varDelta ^{\alpha }_{0+}[x_i](t_k)=\sum \limits _{j=1}^N b_{ij}f_j(t_k,x_j(t_k))+c_i(x_0(t_k)-x_i(t_k))+h_i(t_k), \nonumber \\&x_i(0)=\xi _i\in \mathbb {R}, \,~~i=0,1,\dots ,N, \end{aligned}$$
(14)

for \(k=1,\dots ,M\), where \((x,u)\in C(\mathbb {T};\mathbb {R}^{N+1})\times C(\mathbb {T};\mathbb {R})\) and the functional

$$\begin{aligned} \mathcal {J}^d(x,u) =h\sum \limits _{k=1}^M\Biggl ( \frac{1}{2N^2}\sum \limits _{i,j=1}^N(x_i(t_k)-x_j(t_k))^2 +\frac{1}{2}\sum \limits _{i=1}^N(x_0(t_k)-x_i(t_k))^2 +\frac{\nu }{2}u^2(t_k)\Biggr ), \end{aligned}$$
(15)

where \(\nu >0\) again denotes the weight constant. The right-hand side of (14) is Lipschitz. Therefore, by Lemma IX.1 in [25], the existence and uniqueness of the solution to (14) is guaranteed for every \((u,\xi )\in C(\mathbb {T};\mathbb {R})\times \mathbb {R}^{N+1}\). Moreover, the Lipschitz condition allows us to state the necessary optimality conditions for the solutions to problem (14)–(15) by applying the results proved in [24, 25]. Precisely, let us define the Hamiltonian \(H^d:\mathbb {T}\times \mathbb {R}^{N+1}\times \mathbb {R}\times \mathbb {R}^{N+1}\rightarrow \mathbb {R}\), by \(H^d(t,x,u,\lambda ):=G^d(t,x,u)+\lambda F^d(t,x,u)\), where, for \(k=1,\dots ,M\), \(F^d:\mathbb {T}\times \mathbb {R}^{N+1}\times \mathbb {R}\rightarrow \mathbb {R}^{N+1}\),

$$\begin{aligned} F^d(t_k,x(t_k),u(t_k)):=\left[ \begin{array}{l} u(t_k)\\ \sum \limits _{j= 1}^N b_{ij}f_j(t_k,x_j(t_k))+c_i(x_0(t_k)-x_i(t_k))+h_i(t_k) \end{array}\right] _{i=1,\dots ,N}, \end{aligned}$$

and \(G^d:\mathbb {T}\times \mathbb {R}^{N+1}\times \mathbb {R}\rightarrow \mathbb {R}\), \(G^d(t_k,x(t_k),u(t_k)):=\frac{1}{2N^2}\sum \nolimits _{i,j=1}^N(x_i(t_k)-x_j(t_k))^2 +\frac{1}{2}\sum \nolimits _{i=1}^N(x_0(t_k)-x_i(t_k))^2 +\frac{\nu }{2}u^2(t_k)\).

Theorem 4.3

If the trajectory \(x^*\in C(\mathbb {T};\mathbb {R}^{N+1})\) associated with a control \(u^*\in C(\mathbb {T};\mathbb {R})\) is a solution to (14)–(15), then there exists \(\lambda \in C(\mathbb {T};\mathbb {R}^{N+1})\) such that:

  1. (i)

    \(x^*\) and \(\lambda \) are solutions to the Hamiltonian system

    $$\begin{aligned}&{^{c}}\varDelta ^{\alpha }_{0+}[x](t_k)=\displaystyle \frac{\partial H^d}{\partial \lambda }(t_k,x(t_k),u^*(t_k),\lambda (t_{k-1})),~~k=1,\dots ,M,\nonumber \\&\varDelta ^{\alpha }_{T-}[\lambda ](t_k)=\displaystyle \frac{\partial H^d}{\partial x}(t_{k+1},x(t_{k+1}),u^*(t_{k+1}),\lambda (t_{k})),~~k=0,\dots ,M-1;\nonumber \\ \end{aligned}$$
    (16)
  2. (ii)

    \(\lambda (T)=0\);

  3. (iii)

    the stationary condition \( \lambda _0(t_{k-1})=-\nu u^*(t_k), \quad k=1,\dots ,M,\) holds.

We emphasize that system (16) is not a direct discretization of system (13) by the method explained in Sect. 2 (see [22,23,24,25] for a more in depth discussion about this issue).

5 Illustrative Examples

On the basis of the numerical scheme developed in Sect. 4.1, a Maple code has been written and some fractional systems are now analyzed. In all examples, the computations are performed by assuming that \(\alpha =\frac{1}{2}\). First, we consider systems without a leader. Then, we add the leader but with the assumption that \(u=0\), that is, systems are uncontrolled. Finally, the results obtained with the optimal leader–follower control problem are presented.

Example 5.1

Let us consider a type (5) system with \(N=4\) and \(f_j\), \(j=1,\ldots ,4,\) being identity functions:

$$\begin{aligned} \begin{aligned}&{}^{\mathrm{c}} D^{\alpha }_{0+}[x_1](t)=3x_2(t)-3x_1(t), \quad {}^{\mathrm{c}} D^{\alpha }_{0+}[x_2](t)=x_1(t)-x_2(t),\\&{}^{\mathrm{c}} D^{\alpha }_{0+}[x_3](t)=x_4(t)-x_3(t), \quad {}^{\mathrm{c}} D^{\alpha }_{0+}[x_4](t)=2x_3(t)-2x_4(t), \end{aligned} \end{aligned}$$
(17)

\(x_1(0)=1,~x_2(0)=1.5,~x_3(0)=2,~x_4(0)=2.5.\) As it is shown in Fig. 1 (left), in model (17), the agents’ opinions do not tend to consensus. Therefore, we introduce a virtual leader and consider the following system:

$$\begin{aligned} \begin{aligned}&{}^{\mathrm{c}} D^{\alpha }_{0+}[x_0](t)=0, \quad {}^{\mathrm{c}} D^{\alpha }_{0+}[x_1](t)=3x_2(t)-3x_1(t)+x_0(t)-x_1(t), \\&{}^{\mathrm{c}} D^{\alpha }_{0+}[x_2](t)=x_1(t)-x_2(t),\quad {}^{\mathrm{c}} D^{\alpha }_{0+}[x_3](t)=x_4(t)-x_3(t)+4x_0(t)-4x_3(t),\\&{}^{\mathrm{c}} D^{\alpha }_{0+}[x_4](t)=2x_3(t)-2x_4(t), \end{aligned} \end{aligned}$$
(18)

where \(x_0(0)=5\). The solution to (18) is shown in Fig. 1 (right). Apparently, all agents’ opinions converge to the leader’s opinion, which is constant. Now, let us introduce an external control to (18), i.e., we consider the functional of type (12) and system (18) with the dynamics of the leader given by \({}^{\mathrm{c}} D^{\alpha }_{0+}[x_0](t)=u(t)\). Figure 2 shows a trajectory solution to the considered optimal control problem. Apparently, all agents’ opinions converge to consensus.

Fig. 1
figure 1

The solution to system (17) without the leader (left) and to system (18) with the leader (right)

Fig. 2
figure 2

A trajectory solution to the optimal leader–follower control problem considered in Example 5.1

Example 5.2

Let us introduce noise to the system described in Example 5.1. Namely, let us consider the following system:

$$\begin{aligned} \begin{aligned}&{}^{\mathrm{c}} D^{\alpha }_{0+}[x_1](t)=3x_2(t)-3x_1(t),\quad {}^{\mathrm{c}} D^{\alpha }_{0+}[x_2](t)=x_1(t)-x_2(t)+\frac{1}{4}\sin t,\\&{}^{\mathrm{c}} D^{\alpha }_{0+}[x_3](t)=x_4(t)-x_3(t),\quad {}^{\mathrm{c}} D^{\alpha }_{0+}[x_4](t)=2x_3(t)-2x_4(t)+\frac{1}{4}\cos t. \end{aligned} \end{aligned}$$
(19)

Figure 3 shows solutions to system (19) (left) and to the system with the leader (right). For the case with the control, the solution to the respective optimal control problem is shown in Fig. 4. Observe that, in the presence of noise, agents’ opinions oscillate, but tend to the leader’s opinion in the uncontrolled system. In the case with the control, they are synchronized.

Fig. 3
figure 3

Solutions to systems with noise without the leader (left) and with the leader (right)

Fig. 4
figure 4

A trajectory solution to the optimal leader–follower control problem with noise

Fig. 5
figure 5

The solution to system (20) without the leader (left) and to system (21) with the leader (right)

Fig. 6
figure 6

A candidate trajectory solution to the nonlinear optimal leader–follower control problem considered in Example 5.3

Example 5.3

Finally, we consider the nonlinear model with three interacting agents:

$$\begin{aligned} \begin{aligned}&{}^{\mathrm{c}} D^{\alpha }_{0+}[x_1](t)=\frac{1}{4}(\sin (x_2(t)) -\cos (x_1(t)) ),\\&{}^{\mathrm{c}} D^{\alpha }_{0+}[x_2](t)=\frac{1}{4}(\cos (x_1(t)) -\sin (x_2(t)) ),\\&{}^{\mathrm{c}} D^{\alpha }_{0+}[x_3](t)=0,\quad x_1(0)=1,~x_2(0)=1.5,~x_3(0)=2. \end{aligned} \end{aligned}$$
(20)

In Fig. 5 (left), it is shown that the solution to (20) does not converge to consensus. Because of that, we introduce the leader and consider the following system:

$$\begin{aligned} \begin{aligned}&{}^{\mathrm{c}} D^{\alpha }_{0+}[x_0](t)=0,\quad {}^{\mathrm{c}} D^{\alpha }_{0+}[x_1](t)=\frac{1}{4}(\sin (x_2(t)) -\cos (x_1(t)) )+ x_0(t)-x_1(t),\\&{}^{\mathrm{c}} D^{\alpha }_{0+}[x_2](t)=\frac{1}{4}(\cos (x_1(t)) -\sin (x_2(t)) ),\quad {}^{\mathrm{c}} D^{\alpha }_{0+}[x_3](t)=x_0(t)-x_3(t),\\ \end{aligned} \end{aligned}$$
(21)

together with \(x_0(0)=5,~x_1(0)=1,~x_2(0)=1.5,~x_3(0)=2\). Figure 5 (right) presents the solution to (21). Note that the leader does not force all agents to reach a consensus. Therefore, we introduce the control into the leader dynamics and consider the optimal leader–follower control problem with the functional of type (12). Figure 6 shows a candidate trajectory solutions to the optimal control problem. Apparently, the resulting optimal control introduced to the system via the leader is able to force agents to reach the same opinion.

6 Conclusions

In this work, the agent-based model of opinion formation given by the system of nonlinear fractional differential equations was investigated. We emphasize that, by taking the fractional derivative on the left-hand side of the nonlinear system, the long memory effect was included in the considered model. In order to ensure convergence to consensus, we introduced a virtual leader. Moreover, we proposed optimal control strategies for the leader so that the opinions of other agents approach its opinion in the most efficient way. We have used the fractional derivative defined in the sense of Caputo; however, it would also be interesting to consider systems with other types of fractional derivatives, such as the Hadamard or the Erdélyi–Kober type. Clearly, in practice, the choice of a fractional operator should depend on the particular phenomenon that the model is supposed to describe.