Introduction

Many problems in biology, medicine, chemistry or physics can be described by delay differential equations (DDEs). Unlike ordinary differential equations (ODEs), which are considered at the current state, DDEs contain additionally past states. We refer the readers to [1] to raise awareness about the application of DDEs.

It is challenging to solve DDEs analytically, hence researchers are trying to develop efficient numerical methods to solve such problems. Several numerical methods have been implemented to obtain approximate solutions for DDEs. For instance, an implicit hybrid method with one intra-step point developed in [2], the Runge-Kutta method combined with the Hermite interpolation in [3], or the Adomian decomposition method in [4] were proposed for solving first order DDEs. Also, for second-order DDEs, there are some numerical methods. Related to our work, we just cite Seong and Abdul-Majid [5], which used a two-point multistep block method in the form of the Adams-Moulton method. Also the Adomian decomposition method [6] have been implemented to solve DDEs numerically. In [7], the authors have discussed the existence and uniqueness of solutions for a non-autonomous reaction-diffusion equation with delay. In [8], a dynamic system pendulum taking into account various factors of delay has been considered.

In this work, we propose a numerical method for approximating the following first order DDEs:

$$\begin{aligned}{} & {} y'(x)=f(x,y(x),y(x-\tau (x))),~~~x\in [a,b], \end{aligned}$$
(1)
$$\begin{aligned}{} & {} y(x)=g(x),~~x\le a, \end{aligned}$$
(2)

where g(x) is the initial function and \(\tau (x)\) is the delay term. In most cases, the delay term \(\tau (x)\) is assumed to be either constant or continuous. But in some works, \(\tau (x)\) is considered a piece-wise constant function, and researchers have introduced numerical methods to deal with this kind of problem. In [9], Marzban and Hoseini proposed a numerical method based on block-pulse functions and Lagrange interpolation. In [10], block-pulse functions with Chebyshev polynomials were used for solving piece-wise constant DDEs. In [11], multi-delay and piece-wise constant delay systems are solved based on block-pulse functions and Bernoulli polynomials. Sabermahani and Ordokhani in [12] have studied numerical solutions of DDEs containing piece-wise constant delay by using Lagrange-hybrid functions and the collocation approach.

This paper is organized as follows: “Derivation of the Block Method” section derives an implicit hybrid block method with five intra-step points. In “Analysis of the Proposed Method” section, the main characteristics of the proposed method are investigated. The implementation of the method for DDEs is discussed in “Implementation of the Method for Delay Differential Equations” section. In “Numerical Experiments” section, we present four examples to show the efficiency of the method. Finally, “Conclusion” section is devoted to the conclusion.

Derivation of the Block Method

Most numerical methods for solving ODEs can be adapted to solve DDEs [5] and among them, the implicit block methods. The block methods, initially proposed by Milne [13], have been investigated in recent years by many researchers. Block methods provide numerical approximations at more than one point at a time. In [14, 15], two A-stable two-step hybrid block methods including two intermediate points were presented. Kashkari and Syam [16] obtained an optimized one-step hybrid block method for first-order initial-value problems (IVPs), including three intermediate points.

In this section, we develop an implicit hybrid block method which will be used for solving Eqs. (1) and (2) where \(\tau (x)\) is a piece-wise constant function.

Now, to obtain the block method we assume that the differential equation is of the form \(y'=f(x,y)\). Let \(x_0=a<x_1<\cdots<x_{N-1}<x_N =b\) be a set of equally spaced points on the given interval [ab], where \(x_j=a+j h ,j=0,\ldots ,N\) and \(h=\frac{x_N-x_0}{N}\) is a constant stepsize. Over a subinterval \([x_n,x_{n+1}]\), assume that the exact solution y(x) is approximated by

$$\begin{aligned} P(x)=\sum _{i=0}^{7}a_ix^i, \end{aligned}$$
(3)

where \(a_i\in \mathbb {R}\) are real unknown coefficients. Therefore

$$\begin{aligned} P'(x)=\sum _{i=1}^{7}ia_ix^{i-1}. \end{aligned}$$
(4)

As is the custom, \(y_j\) and \(f_j=f(x_j,y_j)\) are approximations for the exact values \(y(x_j)\) and \(f(x_j,y(x_j))\), respectively. In order to determine the coefficients \(a_i\), we impose the following conditions:

$$\begin{aligned}{} & {} P(x_n)=y_n\end{aligned}$$
(5)
$$\begin{aligned}{} & {} P'(x_{n+\lambda })=y_{n+\lambda },~~~\lambda =0,r,s,u,p,w,1 \end{aligned}$$
(6)

where \(0<r<s<u<p<w<1~\) and \(x_{n+r}=x_n+r h,~x_{n+s}=x_n+s h,~x_{n+u}=x_n+u h,~x_{n+p}=x_n+p h,~x_{n+w}=x_n+w h\) are intra step points. Our choice for the intra points is \(r=\frac{1}{6},~s=\frac{1}{3},u=\frac{1}{2},~p=\frac{2}{3},~w=\frac{5}{6}\). Thus we get the following system:

$$\begin{aligned} \begin{bmatrix} 1 &{} x_{n} &{} x_{n}^{2} &{} x_{n}^{3} &{} x_n^4 &{} x_n^5 &{} x_n^6 &{} x_n^7\\ 0 &{} 1 &{} 2x_{n} &{} 3x_{n}^{2} &{} 4 x_n^3 &{} 5 x_n^4 &{} 6 x_n^5 &{} 7x_n^6\\ 0 &{} 1 &{} 2x_{n+r} &{} 3x_{n+r}^{2}&{} 4 x_{n+r}^3 &{} 5 x_{n+r}^4 &{} 6 x_{n+r}^5 &{} 7x_{n+r}^6 \\ 0 &{} 1 &{} 2x_{n+s} &{} 3x_{n+s}^{2}&{} 4 x_{n+s}^3 &{} 5 x_{n+s}^4 &{} 6 x_{n+s}^5 &{} 7x_{n+s}^6\\ 0 &{} 1 &{} 2x_{n+u} &{} 3x_{n+u}^{2}&{} 4 x_{n+u}^3 &{} 5 x_{n+u}^4 &{} 6 x_{n+u}^5 &{} 7x_{n+u}^6\\ 0 &{} 1 &{} 2x_{n+p} &{} 3x_{n+p}^{2}&{} 4 x_{n+p}^3 &{} 5 x_{n+p}^4 &{} 6 x_{n+p}^5 &{} 7x_{n+p}^6\\ 0 &{} 1 &{} 2x_{n+w} &{} 3x_{n+w}^{2}&{} 4 x_{n+w}^3 &{} 5 x_{n+w}^4 &{} 6 x_{n+w}^5 &{} 7x_{n+w}^6\\ 0 &{} 1 &{} 2x_{n+1} &{} 3x_{n+1}^{2}&{} 4 x_{n+1}^3 &{} 5 x_{n+1}^4 &{} 6 x_{n+1}^5 &{} 7x_{n+1}^6 \end{bmatrix} \begin{bmatrix} a_{0} \\ a_{1} \\ a_{2} \\ a_{3}\\ a_4\\ a_5\\ a_6\\ a_7\\ \end{bmatrix}= \begin{bmatrix} y_{n} \\ f_{n} \\ f_{n+r} \\ f_{n+s} \\ f_{n+u} \\ f_{n+p} \\ f_{n+w} \\ f_{n+1} \end{bmatrix}, \end{aligned}$$

which must be solved to obtain the coefficients \(a_j,~j=0,1,\ldots ,7\). We substitute back into Eq. (3), and after doing the change of variable \(x=x_n+th\), the approximate solution \(P(x_n+th)\) takes the form

$$\begin{aligned}{} & {} P(x_n+th)=C_0y_n+h (C_nf_n+C_rf_{n+r}+C_sf_{n+s}+C_uf_{n+u}\nonumber \\{} & {} \quad +C_pf_{n+p}+C_wf_{n+w}+C_1f_{n+1}), \end{aligned}$$
(7)

where

$$\begin{aligned}{} & {} C_0=1,\\{} & {} C_n={\frac{1}{840}}\,t \left( 7776\,{t}^{6}-31752\,{t}^{5}+52920\,{t}^{4} -46305\,{t}^{3}+22736\,{t}^{2}-6174\,t+840 \right) , \\{} & {} C_r=-{\frac{9}{35}}\,{t}^{2} \left( 216\,{t}^{5}-840\,{t}^{4}+1302\,{t}^{ 3}-1015\,{t}^{2}+406\,t-70 \right) ,\\{} & {} C_s={\frac{9}{280}}\,{t}^{2} \left( 4320\,{t}^{5}-15960\,{t}^{4}+23016\,{ t}^{3}-16135\,{t}^{2}+5460\,t-700 \right) ,\\{} & {} C_u=-{\frac{2}{105}}\,{t}^{2} \left( 9720\,{t}^{5}-34020\,{t}^{4}+45738\, {t}^{3}-29295\,{t}^{2}+8890\,t-1050 \right) ,\\{} & {} C_p={\frac{9}{280}}\,{t}^{2} \left( 4320\,{t}^{5}-14280\,{t}^{4}+17976\,{ t}^{3}-10745\,{t}^{2}+3080\,t-350 \right) \\{} & {} C_w=-{\frac{9}{35}}\,{t}^{2} \left( 216\,{t}^{5}-672\,{t}^{4}+798\,{t}^{3 }-455\,{t}^{2}+126\,t-14 \right) , \\{} & {} C_1={\frac{1}{840}}\,{t}^{2} \left( 7776\,{t}^{5}-22680\,{t}^{4}+25704\,{ t}^{3}-14175\,{t}^{2}+3836\,t-420 \right) . \end{aligned}$$

Now, in order to obtain the main method, we evaluate \(P(x_n+th)\) at the values \(t=r,s,u,p,w,1\), to get the following block hybrid method:

$$\begin{aligned} {\left\{ \begin{array}{ll} y_{n+r}=y_n+h \left( {\frac{19087}{362880}}\,f_n-{\frac{863}{ 362880}}\, f_{n+1}-{\frac{6737}{120960}}\, f_{n+p}+{\frac{2713}{ 15120}}\, f_{n+r}\right. \\ \left. ~~~~~~~ -{\frac{15487}{120960}}\, f_{n+s}+{\frac{293}{2835} }\, f_{n+u}+{\frac{263}{15120}}\, f_{n+w} \right), \\ y_{n+s}={ y_n}+h \left( {\frac{1139}{22680}}\,{ f_n}-{\frac{37}{22680}} \,{ f_{n+1}}-{\frac{269}{7560}}\,{ f_p}+{\frac{47}{189}}\,{ f_r}+ {\frac{11}{7560}}\,{ f_s}+{\frac{166}{2835}}\,{ f_u}+{\frac{11}{945}}\,{ f_w} \right) ,\\ y_{n+u}={ y_n}+h \left( {\frac{137}{2688}}\,{ f_n}-{\frac{29}{13440}}\,{ f_{n+1}}-{\frac{243}{4480}}\,{ f_p}+{\frac{27}{112}}\,{ f_r}+{ \frac{387}{4480}}\,{ f_s}+{\frac{17}{105}}\,{ f_u}+{\frac{9}{ 560}}\,{ f_w} \right) , \\ y_{n+p}={ y_n}+h \left( {\frac{143}{2835}}\,{ f_n}-{\frac{4}{2835}}\,{ f_{n+1}}+{\frac{29}{945}}\,{ f_p}+{\frac{232}{945}}\,{ f_r}+{ \frac{64}{945}}\,{ f_s}+{\frac{752}{2835}}\,{ f_u}+{\frac{8}{ 945}}\,{ f_w} \right) ,\\ y_{n+w}={ y_n}+h \left( {\frac{3715}{72576}}\,{ f_n}-{\frac{275}{72576}} \,{ f_{n+1}}+{\frac{3875}{24192}}\,{ f_p}+{\frac{725}{3024}}\,{ f_r}+{\frac{2125}{24192}}\,{ f_s}+{\frac{125}{567}}\,{ f_u}+{ \frac{235}{3024}}\,{ f_w} \right) ,\\ y_{n+1}={ y_n}+h \left( {\frac{41}{840}}\,{ f_n}+{\frac{41}{840}}\,{ f_{n+1}}+{\frac{9}{280}}\,{ f_p}+{\frac{9}{35}}\,{ f_r}+{\frac{9}{ 280}}\,{ f_s}+{\frac{34}{105}}\,{ f_u}+{\frac{9}{35}}\,{ f_w} \right) . \end{array}\right. } \end{aligned}$$
(8)

Analysis of the Proposed Method

In this section, the major properties of (8) are presented. For order of accuracy, following [17], we define the local truncation error and apply the linear difference operators

$$\begin{aligned} L_{\lambda }[y(x_n),h]=y(x_n+\lambda h)-y(x_n)-h \sum _{j} \beta _{j,\lambda } y'(x_n+j h),~~~\lambda =r,s,u,p,w,1. \end{aligned}$$

where \(\beta _{j,\lambda }\) are the corresponding coefficients as given in system (8). We assume that y(x) is sufficiently differentiable and expand \(y(x_n+\lambda h)\) and \(y'(x_n+jh) ,j=0,r,s,u,p,w,1\) about \(x_n\) using Taylor series. After collecting the coefficients of h, we can obtain the expressions for the local truncation error of each formula as follows:

$$\begin{aligned}{} & {} L_r[y(x_n),h]=\frac{275}{40633270272}h^8y^{(8)}(x_n)+O(h^9),\\{} & {} L_s[y(x_n),h]=\frac{1}{198404640}h^8y^{(8)}(x_n)+O(h^9),\\{} & {} L_u[y(x_n),h]=\frac{1}{167215104}h^8y^{(8)}(x_n)+O(h^9),\\{} & {} L_p[y(x_n),h]=\frac{1}{198404640}h^8y^{(8)}(x_n)+O(h^9),\\{} & {} L_w[y(x_n),h]=\frac{275}{40633270272}h^8y^{(8)}(x_n)+O(h^9),\\{} & {} L_1[y(x_n),h]=\frac{-1}{1567641600}h^9y^{(9)}(x_n)+O(h^{10}). \end{aligned}$$

Consequently, from the above results, the order of the method is 8, although the stage order is 7 and the vector of error constants is:

$$\begin{aligned} C=\left( \frac{275}{40633270272},\frac{1}{198404640},\frac{1}{167215104},\frac{1}{198404640},\frac{275}{40633270272},0\right) ^T. \end{aligned}$$

For stability analysis, we can rearrange the hybrid block method (8) in the following matrix form

$$\begin{aligned} A^{1}Y_{n+1}=A^0Y_n+h(B^0F_n+B^1F_{n+1}), \end{aligned}$$

where

$$\begin{aligned}{} & {} Y_{n+1}=[y_{n+r},y_{n+s},y_{n+u},y_{n+p},y_{n+w},y_{n+1}]^T,\\{} & {} Y_{n}=[y_{n+r-1},y_{n+s-1},y_{n+u-1},y_{n+p-1},y_{n+w-1},y_{n}]^T,\\{} & {} F_{n+1}=[f_{n+r},f_{n+s},f_{n+u},f_{n+p},f_{n+w},f_{n+1}]^T,\\{} & {} F_{n}=[f_{n+r-1},f_{n+s-1},f_{n+u-1},f_{n+p-1},f_{n+w-1},f_{n}]^T, \end{aligned}$$

and

$$\begin{aligned}{} & {} A^1=\begin{bmatrix} 1 &{} 0 &{} 0 &{} 0 &{}0 &{} 0 \\ 0 &{} 1 &{} 0 &{} 0 &{}0 &{} 0\\ 0 &{} 0 &{} 1 &{} 0 &{}0 &{} 0\\ 0 &{} 0 &{} 0 &{} 1 &{}0 &{} 0\\ 0 &{} 0 &{} 0 &{} 0 &{}1 &{} 0\\ 0 &{} 0 &{} 0 &{} 0 &{}0 &{} 1 \end{bmatrix}, \quad A^0=\begin{bmatrix} 0 &{} 0 &{} 0 &{} 0 &{}0 &{} 1 \\ 0 &{} 0 &{} 0 &{} 0 &{}0 &{} 1\\ 0 &{} 0 &{} 0 &{} 0 &{}0 &{} 1\\ 0 &{} 0 &{} 0 &{} 0 &{}0 &{} 1\\ 0 &{} 0 &{} 0 &{} 0 &{}0 &{} 1\\ 0 &{} 0 &{} 0 &{} 0 &{}0 &{} 1 \end{bmatrix},\\{} & {} \quad B^1=\begin{bmatrix} \frac{2713}{15120} &{} \frac{-15487}{120960} &{} \frac{293}{2835} &{} \frac{-6737}{120960} &{}\frac{263}{15120}&{} \frac{-863}{362880} \\ \frac{47}{180} &{} \frac{11}{7560} &{} \frac{166}{2835} &{} \frac{-269}{7560} &{}\frac{11}{945} &{} \frac{-37}{22680}\\ \frac{27}{112} &{} \frac{387}{4480} &{} \frac{17}{105} &{} \frac{-243}{4480} &{}\frac{9}{560} &{} \frac{-29}{13440}\\ \frac{232}{945} &{} \frac{64}{945} &{} \frac{752}{2835} &{} \frac{29}{945} &{}\frac{8}{945} &{} \frac{-4}{2835}\\ \frac{725}{3024} &{} \frac{2125}{24192} &{} \frac{125}{567} &{} \frac{3875}{24192} &{}\frac{235}{3024} &{} \frac{-275}{72576}\\ \frac{9}{35} &{} \frac{9}{280} &{} \frac{34}{105} &{} \frac{9}{280} &{}\frac{9}{35} &{} \frac{41}{840} \end{bmatrix},\\{} & {} \quad B^0=\begin{bmatrix} 0 &{} 0 &{} 0 &{} 0 &{}0 &{} \frac{19087}{362880} \\ 0 &{} 0 &{} 0 &{} 0 &{}0 &{} \frac{1139}{22680}\\ 0 &{} 0 &{} 0 &{} 0 &{}0 &{} \frac{137}{2688}\\ 0 &{} 0 &{} 0 &{} 0 &{}0 &{} \frac{143}{2835}\\ 0 &{} 0 &{} 0 &{} 0 &{}0 &{} \frac{3715}{72576}\\ 0 &{} 0 &{} 0 &{} 0 &{}0 &{} \frac{41}{840} \end{bmatrix}. \end{aligned}$$

The hybrid block method (8), is zero-stable when the roots \(R_j\) of the first characteristic polynomial \(\rho (R)=\det (A^1R-A^0)\) satisfy \(\mid R_j \mid \le 1\) and the multiplicity of every root of modulus one does not exceed 1. For the proposed method, we have \(\rho (R)=R^5(R-1)\), thus the method is zero-stable. Therefore, consistency and zero-stability are obtained for the present method (8), thus it is convergent. The linear stability analysis of the method is determined by applying it to the test problem

$$\begin{aligned} y'=\lambda ~y,~~~Re(\lambda )<0. \end{aligned}$$

It results \(Y_{n+1}=M(\hat{h})Y_n,\) where \(M(\hat{h})=(A^1-\hat{h} B^1)^{-1}(A^0+\hat{h}B^0)\) and \(\hat{h}=\lambda ~h.\) The behavior of the numerical solution \(Y_{n+1}\) will depend on the eigenvalues of \(M(\hat{h})\). The stability matrix \(M(\hat{h})\) has eigenvalues \(\{0,0,0,0,0,\gamma (\hat{h})\}\), where the dominant eigenvalue \(\gamma (\hat{h})\) has the following rational form

$$\begin{aligned} \gamma (\hat{h})&= {} \frac{5}{2}\frac{R(\hat{h})}{Q(\hat{h})},\\ R(\hat{h})&= {} 6215\,{\hat{h}}^{6}+175201\,{\hat{h}}^{5}+2649363\,{\hat{h}}^{4}+28539930\, {\hat{h}}^{3}\\{} & \quad + \,193790250\,{\hat{h}}^{2}+823011840\,\hat{h}+1646023680,\\ Q(\hat{h}) &= 13775\,{\hat{h}}^{6}- 401930\,{\hat{h}}^{5}+6522663\,{\hat{h}}^{4}-69107784\,{\hat{h}}^{3}\\{} & \quad + \, 482831001\,{\hat{h}}^{2}- 2057529600\,\hat{h}+4115059200. \end{aligned}$$

The region of absolute stability S for our method is defined as:

$$\begin{aligned} S=\{ \hat{h}\in \mathbb {C}:~ \mid \gamma (\hat{h})\mid <1\}. \end{aligned}$$

Figure 1 shows the stability region of the presented method. A method is said A-stable if the left-half complex plane is included in the region of the absolute stability. According to the above definition, the proposed method is A-stable (see Fig. 1).

Fig. 1
figure 1

Stability region in the complex plane

Implementation of the Method for Delay Differential Equations

In this section, we explain how to apply the proposed method to solve Eqs. (1) and (2). First we divide the interval [a,  b] in to N equally spaced subintervals \([x_i,~x_{i+1}] ,i=0, \ldots ,N-1\), such that \(h=x_{i+1}-x_i\) is the constant stepsize, and each block includes five hybrid points \(x_{i+r},~x_{i+s},~x_{i+u},~x_{i+p}\) and \(x_{i+w}\).

For \(n=0\), we solve system (8), simultaneously, keeping in mind that we know the initial value \(y_0\) and the values of y(x) for \(x<a\). After solving, we obtain the value \(y_1\). For \(n=1\), we consider the value \(y_1\) as an initial value and solve system (8) to obtain \(y_2\). This process is repeated throughout the integration interval until the final point b is reached. For the delay terms

$$\begin{aligned} y(x_{n+\lambda }-\tau ),~~~~\lambda =0,r,s,u,p,w,1, \end{aligned}$$

when \(x_ {n+\lambda }-\tau \le a\), the initial function g(x) is evaluated to get the solution at the delay argument \(y(x_{n+\lambda }-\tau )\). If \(x_{n+\lambda }-\tau >a\), the delay term depends on the location of \(x_{n+\lambda }-\tau\). If \(x_{n+\lambda }-\tau\) is one of the mesh points, we can recall its value which we had stored earlier. Otherwise, it is sufficient to find the subinterval \([x_k,~x_{k+1}]\), such that

$$\begin{aligned} x_k< x_{n+\lambda }-\tau <x_{k+1}. \end{aligned}$$

Then, we can approximate \(y(x_{n+\lambda }-\tau )\) through interpolation based on the points:

$$\begin{aligned} (x_{k+\lambda },y_{k+\lambda })~,\lambda =0,r,s,u,p,w,1, \end{aligned}$$

which had been obtained previously.

Numerical Experiments

In this section, using several numerical examples, the performance of the proposed method (8) is evaluated. Our computations have been done in Maple17 using 20 digits in the computations.

Example 1

Consider the following linear piece-wise constant delay differential equation [9,10,11,12]:

$$\begin{aligned} y'(x)=-5y(x)-5y(x-\tau (x))+2, ~~x\in [0,2], \end{aligned}$$
(9)

with \(y(0)=1\) and

$$\begin{aligned} \tau (x)= {\left\{ \begin{array}{ll} 0~~~~0\le x< 0.8\\ 0.3~~~0.8\le x<1.4\\ 0.6~~~1.4\le x<1.7\\ 0.9~~~1.7\le x\le 2. \end{array}\right. } \end{aligned}$$
(10)

The exact solution of this equation is

$$\begin{aligned} y(x)= {\left\{ \begin{array}{ll} 0.2+0.8e^{-10x}~,~~~0\le x\le 0.8,\\ 0.2+0.8e^{3-10x}+0.8e^{-4}(1-e^{3})e^{-5x}~,~~0.8\le x<1.1,\\ 0.2+0.8e^{6-10x}-4~e^{-2.5}(1-e^{3})xe^{-5x}\\ ~~~~~+0.8(1-e^{3})(6.5e^{-2.5}+e^{-4})e^{-5x}~,~~1.1\le x<1.4,\\ 0.2+0.8e^{9-10x}-4e^{-1}(1-e^{3})xe^{-5x}\\ ~~~~~+0.8(1-e^{3})(8e^{-1}-0.5e^{-2.5}+e^{-4})e^{-5x}~,~~1.4\le x<1.7,\\ 0.2+0.8e^{12-10x}-4e^{0.5}(1-e^{3})xe^{-5x}\\ ~~~~+0.8(1-e^3)(9.5e^{0.5}-0.5e^{-1}-0.5e^{-2.5}+e^{-4})e^{-5x}~,~~~~~1.7\le x \le 2. \end{array}\right. } \end{aligned}$$
(11)

Table 1 presents the comparison between the maximum absolute error and CPU time obtained from our method (8) and results in [10, 12]. It is clear that the proposed method is the most efficient. Figure 2 shows the absolute errors (AE) for \(h=0.05,0.1\). To check the theoretical order of convergence we have considered the usual formula to obtain the numerical rate of convergence, given by

$$\begin{aligned} ROC= \log _2\left( \frac{MAE_{2h}}{MAE_h}\right) , \end{aligned}$$

where \(MAE_h\) is the maximum absolute error over the integration interval taking a stepsize h. For this problem we get \(ROC=8.023\), which agrees with the theoretical findings.

Table 1 Comparison of the maximum absolute errors and CPU time for example 1
Fig. 2
figure 2

Absolute error of example 1, for \(h=0.05\) (left) and \(h=0.1\) (right)

Example 2

Consider the following piece-wise constant delay differential equation [10]:

$$\begin{aligned} {\left\{ \begin{array}{ll} y'(x)=y(x-\tau )+1,~~0\le x\le 1\\ y(x)=0,~~x\le 0 \end{array}\right. } \end{aligned}$$
(12)

with

$$\begin{aligned} \tau (x)={\left\{ \begin{array}{ll} 0.1,~~~0<x<0.35,\\ 0.3,~~~0.35\le x<0.7,\\ 0.5,~~~0.7\le x\le 1. \end{array}\right. } \end{aligned}$$
(13)

For the above equation, the exact solution is

$$\begin{aligned} y(x)= {\left\{ \begin{array}{ll} x~,~~~0\le x< 0.1,\\ \frac{1}{200}+\frac{9}{10}x+\frac{x^2}{2}~,~~0.1\le x<0.2,\\ \frac{11}{3000}+\frac{23}{25}x+\frac{2}{5}x^2+\frac{x^3}{6}~,~~0.2\le x<0.3,\\ \frac{961}{240000}+\frac{1831}{2000}x+\frac{169}{400}x^2+\frac{7}{60}x^3+\frac{x^4}{24}~ ,~~0.3\le x<0.35,\\ \frac{290161}{3840000}+\frac{7}{10}x+\frac{1}{2}x^2~,~~~~0.35\le x<0.4,\\ \frac{83067}{1280000}+\frac{39}{50}x+\frac{3}{10}x^2+\frac{1}{6}x^3~,~~~0.4\le x<0.5,\\ \frac{259201}{3840000}+\frac{911}{1200}x+\frac{29}{80}x^2+\frac{1}{12}x^3+\frac{1}{24}x^4~,~~0.5\le x<0.6,\\ \frac{6417817}{96000000}+\frac{22937}{30000}x+\frac{689}{2000}x^2+\frac{17}{150}x^3+\frac{1}{160}x^4 +\frac{1}{120}x^5~,~~~~0.6\le x<0.65,\\ \frac{1070467}{48000000}+\frac{3496561}{3840000}x+\frac{1}{5}x^2+\frac{1}{6}x^3~,~~~0.65\le x<0.7,\\ \frac{37190303}{192000000}+\frac{3737}{6000}x+\frac{129}{400}x^2+\frac{1}{20}x^3 +\frac{1}{24}x^4~,~~~~0.7\le x< 0.8,\\ \frac{2444401}{128000000}+\frac{6399}{10000}x+\frac{1679}{6000}x^2+\frac{31}{300}x^3+\frac{1}{120}x^4 +\frac{1}{120}x^5~,~~~~~~0.8\le x<0.85,\\ \frac{7103237}{64000000}+\frac{3266161}{3840000}x+\frac{1}{10}x^2+\frac{1}{6}x^3~,~~0.85\le x<0.9,\\ \frac{8852837}{64000000}+\frac{2799601}{3840000}x+\frac{121}{400}x^2+\frac{1}{60}x^3+\frac{1}{24}x^4~,~~~~0.9\le x \le 1. \end{array}\right. } \end{aligned}$$
(14)

In order to solve this problem numerically, we choose \(h=0.05\). Plot of the absolute error for this problem is shown in Fig. 3.

Fig. 3
figure 3

Absolute error of example 2, for \(h=0.05\)

Example 3

Consider the following delay differential equation [11]:

$$\begin{aligned} {\left\{ \begin{array}{ll} y'(x)=-y(x)-2y(x-\frac{1}{4})+2u(x-\frac{1}{4}),\\ y(x)=u(x)=0,~~-\frac{1}{4}\le x< 0,\\ u(x)=1,~~~x>0 \end{array}\right. } \end{aligned}$$
(15)

The exact solution for this problem is

$$\begin{aligned} y(x)= {\left\{ \begin{array}{ll} 0~,~~~0\le x \le \frac{1}{4},\\ 2-2e^{\frac{1}{4}-x}~,~~~~\frac{1}{4}\le x \le \frac{1}{2},\\ -2-2e^{\frac{1}{4}-x}+(2+4x)e^{\frac{1}{2}-x}~,~~~~\frac{1}{2}\le x\le \frac{3}{4},\\ 6-2e^{\frac{1}{4}-x}+(2+4x)e^{\frac{1}{2}-x}-(\frac{14}{4}+2x+4x^2)e^{\frac{3}{4}-x} ~,~~~~\frac{3}{4}\le x\le 1. \end{array}\right. } \end{aligned}$$
(16)

The absolute errors for \(h=0.05\) are given in Fig. 4.

Fig. 4
figure 4

Absolute error of example 3, for \(h=0.05\)

In order to compare the performance of the proposed method, Table 2 shows the absolute errors obtained with the methods in [11, 18, 19].

Table 2 Comparison between the absolute errors in our method and some other methods, for example 3

Example 4

Consider the following nonlinear piece-wise constant delay differential equation [20]:

$$\begin{aligned} y'(x)=xy(x-\tau (x))+x y^2(x-\tau (x))+y^3(x-\tau (x))+u(x), \quad 0\le x\le 1, \end{aligned}$$
(17)

where \(y(0)=1\) and \(y(x)=-1\) for \(x<0\), and

$$\begin{aligned} u(x)= {\left\{ \begin{array}{ll} 1,~~~~0\le x< 0.8,\\ -1,~~~~0.8\le x\le 1, \end{array}\right. } ;~~~~ \tau (x)={\left\{ \begin{array}{ll} 0.4,~~~~0\le x< 0.8,\\ 0.8,~~~~0.8\le x\le 1 .\end{array}\right. } \end{aligned}$$
(18)

The exact solution is

$$\begin{aligned} y(x)={\left\{ \begin{array}{ll} 1~,~~~0\le x<0.4,\\ \frac{1}{25}+2x+x^2~,~~~0.4\le x<0.8,~~~\\ \frac{41}{25}+x^2~,~~~~0.8\le x\le 1. \end{array}\right. } \end{aligned}$$
(19)

By employing the presented method to solve this problem, we can obtain numerical solution \(y_{i+\lambda }\) for mesh points \(x_{i+\lambda }, i=1,2,\dots ,N~~, \lambda =r,s,u,p,w\). Table 3 shows the absolute errors for \(h=0.1\).

Table 3 The absolute errors of example 4, for \(h=0.1\)

Conclusion

In this study, a one-step hybrid block method with five intra-points has been developed. This method, combined with the appropriate interpolation, has been implemented to solve first-order delay differential equations containing a piece-wise constant delay. The main features of the method such as consistency, zero-stability and linear stability have been investigated. We have solved some examples with piece-wise constant delays. The numerical results indicate the efficiency of the proposed method and its suitability for solving this type of problem.