Keywords

These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

1 Introduction

In this work, we are dealing with the numerical solutions of the following nonlinear partial differential equation, namely a Nonlinear Klein-Gordon equation:

$$\begin{aligned} u_{tt}+\alpha u_{xx}+\beta u+\gamma u^{k}=f(x,t), \qquad x\in \varOmega =[-1,1], \,\, t\in (0,T], \end{aligned}$$
(1)

subject to the initial conditions

$$\begin{aligned} \left\{ \begin{array}{ll} u(x,0)=g_{1}(x), &{} x\in \varOmega , \\ u_{t}(x,0)=g_{2}(x), &{} x\in \varOmega , \end{array} \right. \end{aligned}$$
(2)

and Dirichlet boundary condition

$$\begin{aligned} u(x,t)=h(x,t), \ x \in \partial \varOmega , \ t\in (0,T], \end{aligned}$$
(3)

where \(\alpha \), \(\beta \) and \(\gamma \) are nonzero real constants and f is a known analytic function. Nonlinear phenomena occur in a wide variety of scientific applications such as plasma physics, solid state physics, fluid dynamics and chemical kinetics [1]. The nonlinear Klein-Gordon equation is one of the important models in quantum mechanics and mathematical physics. The equation has received considerable attention in studying solitons and condensed matter physics, in investigating the interaction of solitons in collisionless plasma, the recurrence of initial states, and in examining the nonlinear wave equations [2].

There are a lot of studies on the numerical solution of initial and initial-boundary problems of the linear or nonlinear Klein-Gordon equation. For instance, Chowdhury and Hashim [3] employed the homotopy-perturbation method to obtain approximate solutions of the Klein-Gordon and sine-Gordon equations. Four finite difference schemes for approximating the solution of nonlinear Klein-Gordon equation were discussed in [4]. Deeba and Khuri [5] presented a decomposition scheme for obtaining numerical solutions of the Eq. (1). In [6], a spline collocation approach for the numerical solution of a generalized nonlinear Klein-Gordon equation was investigated. Dehghan and Shokri [7] proposed a numerical scheme to solve the one-dimensional nonlinear Klein-Gordon equation with quadratic and cubic nonlinearity using the collocation points and approximating the solution by Thin Plate Splines radial basis functions. Authors in [8] considered a numerical method based on the cubic B-splines collocation technique on the uniform mesh points. Lakestani and Dehghan [9] presented two numerical techniques. The first one is Mixed Finite Difference in time and Collocation Methods using cubic B-spline functions in space (MFDCM) and the second one is fully Collocation Method (CM) which approximates the solution in both space and time variables using cubic B-spline functions. A fully implicit and discrete energy conserving finite difference scheme for the solution of an initial-boundary value problem of the nonlinear Klein-Gordon equation derived by Wong et al. [10]. A three-level spline-difference scheme to solve the one dimensional Klein-Gordon equation which is based on using the finite difference approximation for the time derivative and the spline approximation for the second-order spatial derivative was derived by authors in [11]. Most recently, authors in [12] proposed a spectral method using Legendre wavelets.

In this article we study the application of polynomial scaling functions and wavelets for computation of numerical solution of nonlinear Klein-Gordon equation. A numerical technique based on the finite difference and Collocation methods is presented. At the first stage, our method is based on the discretization of the time variable by means of the Crank-Nicolson method and freezing the coefficients of the resulting ordinary differential equation at each time step. At the second stage, we use the Wavelet-Collocation method on the yield linear ordinary differential equations at each time step resulting from the time semidiscretization. Considering this basis being wavelet functions, our method is essentially a spectral method.

Polynomial scaling and wavelet functions are rarely used in the contexts of numerical computation [13]. One of the advantages of using polynomial scaling function as expansion functions is the good representation of smooth functions by finite Chebyshev expansion. The Crank-Nicolson method is an unconditionally stable, implicit numerical scheme with second-order accuracy in both time and space. Our approach consists of reducing the Klein-Gordon equation to a set of algebraic equations by expanding the approximate solution in terms of wavelet functions with unknown coefficients. The operational matrix of derivative is presented. This matrix together with the Collocation method are then utilized to evaluate the unknown coefficients of the solution at each time step. Finally, the convergence analysis of the proposed method for the Eq. (1) is developed.

The organization of this paper is as follows. In Sect. 2, we describe the polynomial scaling and wavelet functions on \(\left[ -1,1\right] \) and some basic properties. In Sect. 3, the proposed method is used to approximate the solution of the problem. As a result, a set of algebraic equations is formed and a solution of the considered problem is introduced at each time step. In Sect. 4, the error bounds of the method based on the Crank-Nicolson and polynomial wavelets are presented. In Sect. 5, we discuss the accuracy and efficiency of the employed method by applying to several test problems. A brief conclusion is given at the end of the paper in Sect. 6.

2 Preliminary

In this section, we shall give a brief introduction of the polynomial wavelets on \([-1,1]\) and their basic properties [14]. Also the construction of the operational matrix of the derivative and some approximation results [15] are presented.

2.1 Polynomial Wavelets

Suppose that \(T_{n}\) and \(U_{n}\) be the following Chebyshev polynomials of the first and second kind respectively,

$$\begin{aligned} T_{n}(x)=\cos (n\arccos (x))\ \ \ \text {and}\ \ \ U_{n-1}(x)=\frac{\sin (n\arccos (x))}{\sin (\arccos (x))}, \end{aligned}$$

here to introduce polynomial scaling function we need \(\omega _{j}\) which is defined as:

$$\begin{aligned} \omega _{j}(x)=(1-x^{2})U_{2^{j}-1}(x)=\frac{(1-x^{2})}{2^{j}} T_{2^{j}}^{\prime }(x),\ \ \ \ j=0,1,2,\ldots . \end{aligned}$$

The zeros of \(\omega _j(x)\) are \(x_k=\cos (\frac{k\pi }{2^j})\) for \( k=0,1,\ldots ,2^j\) and it should be pointed out that the zeros of \(\omega _j\) are also zeros of \(\omega _{j+1}\).

Let

$$\begin{aligned} \varepsilon _{j,l}=\left\{ \begin{array}{ll} \frac{1}{2} &{} \text {for}\ l=0\ \text {or}\ l=2^{j} \\ 1 &{} \text {for}\ l=1,2,\ldots ,2^{j}-1 \end{array} \right. \end{aligned}$$

for any \(j\in \mathbb {N}_{0}=\mathbb {N}\cup \{0\}\), the polynomial scaling functions are defined as:

$$\begin{aligned} \phi _{j,l}(x)=\frac{\omega _{j}(x)}{2^{j}(-1)^{l+1}(x-x_{l})}\varepsilon _{j,l}, \,\, l=0,1,\ldots ,2^{j}. \end{aligned}$$
(4)

Given \(j\in \mathbb {N}_{0}\), the space of polynomial scaling functions on \( [-1,1]\) is defined by \(V_{j}=\text {span}\{\phi _{j,l}:l=0,1,\ldots ,2^{j}\}\).

It is easy to see that the spaces \(V_{j}=\Pi _{2^{j}}\) where \(\Pi _{n}\) denotes the set of all polynomials of degree at most n. The interpolatory property of this functions which helps to accelerate the computations is:

$$\begin{aligned} \phi _{j,l}(\cos (\frac{k\pi }{2^{j}}))=\delta _{k,l},\quad k,l=0,1,\ldots ,2^{j}. \end{aligned}$$
(5)

The wavelet spaces are defined by \(W_{j}=\text {span}\{\psi _{j,l}:l=0,1,\ldots ,2^{j}-1\}\), where

$$\begin{aligned} \psi _{j,l}(x)=\frac{T_{2^{j}}(x)}{2^{j}(x-\cos ((2l+1)\pi /2^{j+1}))}\left( 2\omega _{j}(x)-\omega _{j}\left( \cos \frac{(2l+1)\pi }{2^{j+1}}\right) \right) . \end{aligned}$$

The same interpolating property holds with the zeros of \(\omega _{j+1}\) as:

$$\begin{aligned} \psi _{j,l}(\cos (\frac{(2k+1)\pi }{2^{j+1}}))=\delta _{k,l},\quad k,l=0,1,\ldots ,2^{j}-1. \end{aligned}$$

We note that \(\mathrm {dim}W_{j}=2^{j}\) and \(\mathrm {dim}V_{j}=2^{j+1}\), also for all \(j\in \mathbb {N}_{0}\) we have \(V_{j+1}=V_{j}\oplus W_{j}\) and by denoting \(W_{-1}\) as \(V_{0}\) we obtain

$$\begin{aligned} \Pi _{2^{j+1}}=V_{j+1}=\bigoplus _{k=-1}^{j}W_{k}. \end{aligned}$$
(6)

2.2 Function Approximation

For any \(j\in \mathbb {N}_{0}\), the operator \(L_{j}\) mapping any real-valued function f(x) on \([-1,1]\) into the space \(V_{j}\) by the Lagrange formula

$$\begin{aligned} L_{j}f(x)=\sum _{l=0}^{2^{j}}f(x_{l})\phi _{j,l}(x)=U^{T}\varPhi _{j}(x), \end{aligned}$$
(7)

where U and \(\varPhi _{j}\) are vectors with \(2^{j}+1\) components as:

$$\begin{aligned} U=\left[ f(x_{0}),f(x_{1}),...,f(x_{2^{j}})\right] ^{T}, \end{aligned}$$
(8)
$$\begin{aligned} \varPhi _{j}(x)=\left[ \phi _{j,0}(x),\phi _{j,1}(x),...,\phi _{j,2^{j}}(x) \right] ^{T}. \end{aligned}$$
(9)

Considering (6) it follows that

$$\begin{aligned} L_{j}f(x)=\sum _{k=0}^{1}a_{k}\phi _{0,k}(x)+\sum _{l=0}^{j-1}\sum _{i=0}^{2^{l}-1}b_{l,i}\psi _{l,i}(x)=C^{T}\varPsi _{j-1}(x), \end{aligned}$$
(10)

where \(\phi _{0,k}(x)\) and \(\psi _{l,i}(x)\) are scaling and wavelet functions, respectively, and C and \(\varPsi _{j-1}\) are vectors with \(2^{j}+1\) components as:

$$\begin{aligned} C=\left[ a_{0},a_{1},b_{0,0},b_{1,0},b_{1,1},...,b_{j-1,2^{j-1}-1}\right] ^{T}, \end{aligned}$$
(11)
$$\begin{aligned} \varPsi _{j-1}(x)=\left[ \phi _{0,0},\phi _{0,1},\psi _{0,0},\psi _{1,0},\psi _{1,1},...,\psi _{j-1,2^{j-1}-1}\right] ^{T}. \end{aligned}$$
(12)

The vector C can be obtained by considering,

$$\begin{aligned} \varPsi _{j-1}=\mathbf {G}\varPhi _{j}, \end{aligned}$$
(13)

where \(\mathbf {G}\) is a \((2^{j}+1)\times (2^{j}+1)\) matrix, which can be determined as follows. Using the two scale relations and decomposition between polynomial scaling and wavelet functions represented in [14, pp. 100 ], we have

$$\begin{aligned} \varPhi _{j-1}=\lambda _{j-1}\varPhi _{j},\ \ \ \ \ \ \ \ \ \ \ \ \ \varPsi _{j-1}=\mu _{j-1}\varPhi _{j}, \end{aligned}$$
(14)

where \(\lambda _{j-1}\) is a \((2^{j-1}+1)\times (2^{j}+1)\) matrix and \(\mu _{j-1}\) is a \((2^{j-1})\times (2^{j}+1)\) matrix. Following [16] and by using Eqs. (13) and (14), we obtain

$$\begin{aligned} \mathbf {G}= \begin{bmatrix} \lambda _{0}\times \lambda _{1}\times \cdots \times \lambda _{j-1} \\ \mu _{0}\times \lambda _{1}\times \cdots \times \lambda _{j-1} \\ \vdots \\ \mu _{j-3}\times \mu _{j-2}\times \lambda _{j-1} \\ \mu _{j-2}\times \mu _{j-1} \\ \mu _{j-1} \end{bmatrix} . \end{aligned}$$

By using Eqs. (13) and (7), we get

$$\begin{aligned} L_{j}f(x)=U^{T}\varPhi _{j}=U^{T}\mathbf {G}^{-1}\varPsi _{j-1}, \end{aligned}$$

so that we have \(C^{T}=U^{T}\mathbf {G}^{-1}\).

Interpolation properties of polynomial scaling functions could help to obtaining the coefficients very fast, because it just needs to replacing the variable of function by the zeros of \(\omega _{j}(x)\) and no need of integration. In the rest of the paper for simplicity and abbreviation we denote \(\varPhi _{j}(x)\) and \(\varPsi _{j-1}(x)\) by \(\varPhi (x)\) and \(\varPsi (x)\), respectively.

2.3 Operational Matrix of Derivative

Polynomial scaling functions operational matrix of derivative was derived in [15]. Here, we just list the theorem and a corollary as follows.

Theorem 1

The differentiation of vector \(\varPhi (x)\) in (9) can be expressed as:

$$\begin{aligned} \varPhi ^{\prime }(x)=D_{\phi }\varPhi (x), \end{aligned}$$
(15)

where \(D_{\phi }\) is \((2^{j}+1)\times (2^{j}+1)\) and the entries of operational matrix of derivative for polynomial scaling functions \(D_{\phi }\) are:

$$\begin{aligned} d_{k,l}=\left\{ \begin{array}{ll} \overset{2^{j}}{\sum \limits _{i=0,\text { }i\ne k}}\frac{1}{x_{l}-x_{i}}, &{} \text {if}\ \ l=k, \\ 2^{2^{j}-j-1}(-1)^{k}\varepsilon _{j,k}\prod \limits _{r=0,\text { }r\ne l,k}^{2^{j}}(x_{l}-x_{r}), &{} \text {if}\ \ l\ne k. \end{array} \right. \end{aligned}$$

Proof

See [15].

Corollary 2

Using matrix \(\mathbf {G}\) the operational matrix of derivative for polynomial wavelets can be represented as:

$$\begin{aligned} D_{\psi }=\mathbf {G}^{-1}D_{\phi }\mathbf {G}. \end{aligned}$$
(16)

3 The Polynomial Wavelet Method (PWM)

In this section, we solve nonlinear partial differential equation (1) on a bounded domain. For this end, we use finite difference method for one variable to reduce these equations to a system of ordinary differential equations, then we solve this system and find the solution of the given Klein-Gordon equation at the points \(t_n=n\delta t\) for \(\delta t=\frac{T-0}{ N}\), \(n=0, 1, \ldots , N\).

In order to perform temporal discretization, we discretize (1) according to the following \(\theta \)-weighted type scheme

$$\begin{aligned} \frac{u^{n+1}-2u^{n}+u^{n-1}}{(\delta t)^{2}}+\theta \left( \alpha u_{xx}^{n+1}+\beta u^{n+1}\right) +(1-\theta )\left( \alpha u_{xx}^{n}+\beta u^{n}\right) +\gamma (u^{n})^{k}=f(x,t_{n}), \end{aligned}$$
(17)

where \(\delta t\) is the time step size and \(u^{n+1}\) is used to show \( u(x,t+\delta t)\). By choosing \(\theta =\frac{1}{2}\) (Crank-Nicolson scheme) and rearranging Eq. (17) we obtain

$$\begin{aligned} u^{n+1}+\frac{\beta (\delta t)^{2}}{2}u^{n+1}+\frac{\alpha (\delta t)^{2}}{2}u_{xx}^{n+1}= & {} \left( 2-\frac{\beta (\delta t)^{2}}{2} \right) u^{n}-\frac{\alpha (\delta t)^{2}}{2}u_{xx}^{n} \nonumber \\&-\gamma (\delta t)^{2}(u^{n})^{k}-u^{n-1}+(\delta t)^{2}f(x,t_{n}). \end{aligned}$$
(18)

Using Eq. (7), the approximate solution for \(u^{n}(x)\) via scaling functions is represented by formula

$$\begin{aligned} L_{j}u^{n}(x)=\mathbf {U}_{n}^{T}\varPhi (x), \end{aligned}$$
(19)

where vectors \(\mathbf {U}_{n}\) and \(\varPhi (x)\) are defined as (8) and (9) respectively.

For the derivatives of \(u^{n}(x)\) by using (15) we can write the following relations,

$$\begin{aligned} L_{j}u_{x}^{n}(x)=\mathbf {U}_{n}^{T}\varPhi ^{\prime }(x)=\mathbf {U} _{n}^{T}D_{\phi }\varPhi (x), \end{aligned}$$
(20)
$$\begin{aligned} L_{j}u_{xx}^{n}(x)=\mathbf {U}_{n}^{T}\varPhi ^{\prime \prime }(x)=\mathbf {U} _{n}^{T}D_{\phi }^{2}\varPhi (x). \end{aligned}$$
(21)

Replacing Eqs. (19) and (21) in Eq. (18) we obtain

$$\begin{aligned}&\mathbf {U}_{n+1}^{T}\varPhi (x)+\frac{\beta (\delta t)^{2}}{2}\mathbf {U} _{n+1}^{T}\varPhi (x)+\frac{\alpha (\delta t)^{2}}{2}\mathbf {U} _{n+1}^{T}D_{\phi }^{2}\varPhi (x) \nonumber \\= & {} \left( 2-\frac{\beta (\delta t)^{2}}{2}\right) \mathbf {U}_{n}^{T}\varPhi (x)- \frac{\alpha (\delta t)^{2}}{2}\mathbf {U}_{n}^{T}D_{\phi }^{2}\varPhi (x)-\gamma (\delta t)^{2}(\mathbf {U}_{n}^{T}\varPhi (x))^{k} \\&-\mathbf {U}_{n-1}^{T}\varPhi (x)+(\delta t)^{2}f(x,t_{n}). \nonumber \end{aligned}$$
(22)

Substituting Eq. (13) into Eq. (22), we change current base to the polynomial wavelets bases

$$\begin{aligned}&\mathbf {U}_{n+1}\left[ I+\frac{\beta (\delta t)^{2}}{2}I+\frac{\alpha (\delta t)^{2}}{2}D_{\phi }^{2}\right] \mathbf {G}^{-1}\varPsi (x) \nonumber \\= & {} \left( 2-\frac{\beta (\delta t)^{2}}{2}\right) \mathbf {U}_{n}^{T}\mathbf {G }^{-1}\varPsi (x)-\frac{\alpha (\delta t)^{2}}{2}\mathbf {U}_{n}^{T}D_{\phi }^{2} \mathbf {G}^{-1}\varPsi (x) \\&-\gamma (\delta t)^{2}(\mathbf {U}_{n}^{T}\mathbf {G}^{-1}\varPsi (x))^{k}- \mathbf {U}_{n-1}^{T}\mathbf {G}^{-1}\varPsi (x)+(\delta t)^{2}f(x,t_{n}). \nonumber \end{aligned}$$
(23)

By collocating Eq. (23) in the points \(x_{k}=\cos (\frac{k\pi }{2^{j}} ),\ k=0,1,\ldots ,2^{j},\) we get,

$$\begin{aligned}&\mathbf {U}_{n+1}\left[ I+\frac{\beta (\delta t)^{2}}{2}I+\frac{\alpha (\delta t)^{2}}{2}D_{\phi }^{2}\right] \mathbf {G}^{-1}\varPsi (x_{k}) \nonumber \\= & {} \left( 2-\frac{\beta (\delta t)^{2}}{2}\right) \mathbf {U}_{n}^{T}\mathbf {G }^{-1}\varPsi (x_{k})-\frac{\alpha (\delta t)^{2}}{2}\mathbf {U}_{n}^{T}D_{\phi }^{2}\mathbf {G}^{-1}\varPsi (x_{k}) \\&-\gamma (\delta t)^{2}(\mathbf {U}_{n}^{T}\mathbf {G}^{-1}\varPsi (x_{k}))^{k}- \mathbf {U}_{n-1}^{T}\mathbf {G}^{-1}\varPsi (x_{k})+(\delta t)^{2}f(x_{k},t_{n}), \nonumber \end{aligned}$$
(24)

which represents a system of \((2^{j}+1)\times (2^{j}+1)\) equations.

Using Eq. (19) in (3) we have

$$\begin{aligned} \mathbf {U}_{n+1}^{T}\mathbf {G}^{-1}\varPsi (-1)=h(-1,t_{n+1}), \end{aligned}$$
(25)
$$\begin{aligned} \mathbf {U}_{n+1}^{T}\mathbf {G}^{-1}\varPsi (1)=h(1,t_{n+1}). \end{aligned}$$
(26)

Because the rank of matrix \(D_{\phi }\) is \(2^{j}\) and the rank of \(D_{\phi }^{2}\) is \(2^{j}-1\) we replace Eqs. (25)–(26) instead of first and last equations of the system (24), so we finally obtain a following matrix form of equations,

$$\begin{aligned} \mathscr {A}_{n}\mathbf {U}_{n+1}=\mathscr {B}_{n},\ \ \ \ \ \ \ \ \ \ \ n=1,2,\ldots \end{aligned}$$
(27)

where \(\mathscr {A}_{n}\) is a matrix with dimension \((2^{j}+1)\times (2^{j}+1) \) as,

$$\begin{aligned} \mathscr {A}_{n}= \begin{bmatrix} \varPsi ^{T}(-1)(\mathbf {G}^{-1})^{T} \\ \varPsi ^{T}(x_{1})(\mathbf {G}^{-1})^{T}\left[ I+\frac{\beta (\delta t)^{2}}{2} I+\frac{\alpha (\delta t)^{2}}{2}D_{\phi }^{2}\right] ^{T} \\ \vdots \\ \varPsi ^{T}(x_{2^{j}-1})(\mathbf {G}^{-1})^{T}\left[ I+\frac{\beta (\delta t)^{2}}{2}I+\frac{\alpha (\delta t)^{2}}{2}D_{\phi }^{2}\right] ^{T} \\ \varPsi ^{T}(1)(\mathbf {G}^{-1})^{T} \end{bmatrix} \end{aligned}$$

and

$$\begin{aligned} \mathscr {B}_{n}= \begin{bmatrix} h(-1,t_{n+1}) \\ \varGamma _{1} \\ \vdots \\ \varGamma _{2^{j}-1} \\ h(1,t_{n+1}) \end{bmatrix} \end{aligned}$$

with

$$\begin{aligned} \varGamma _{i}=\left( 2-\frac{\beta (\delta t)^{2}}{2}\right) \mathbf {U}_{n}^{T} \mathbf {G}^{-1}\varPsi (x_{i})-\frac{\alpha (\delta t)^{2}}{2}\mathbf {U} _{n}^{T}D_{\phi }^{2}\mathbf {G}^{-1}\varPsi (x_{i})-\gamma (\delta t)^{2}( \mathbf {U}_{n}^{T}\mathbf {G}^{-1}\varPsi (x_{i}))^{k} \end{aligned}$$
$$\begin{aligned} -\mathbf {U}_{n-1}^{T}\mathbf {G}^{-1}\varPsi (x_{i})+(\delta t)^{2}f(x_{i},t_{n}),\ \ \ \ \ i=1,\ldots ,2^{j}-1. \end{aligned}$$

Using the first initial condition of Eq. (2), we have

$$\begin{aligned} \mathbf {U}_{0}^{T}\mathbf {G}^{-1}\varPsi (x)=g_{1}(x), \end{aligned}$$
(28)

By using the second initial condition of Eq. (2), one can get

$$\begin{aligned} \frac{u^{1}(x)-u^{-1}(x)}{2(\delta t)^{2}}=g_{2}(x),\ \ \ \ \ \ \ \ \ x\in \varOmega . \end{aligned}$$
(29)

Equation (29) can be rewritten as

$$\begin{aligned} \mathbf {U}_{-1}^{T}\mathbf {G}^{-1}\varPsi (x)=\mathbf {U}_{1}^{T}\mathbf {G} ^{-1}\varPsi (x)-2(\delta t)^{2}g_{2}(x). \end{aligned}$$
(30)

Equation (27) using Eqs. (28) and (30) as the starting points, gives the system of equations with \(2^{j}+1\) unknowns and equations, which can be solved to find \(\mathbf {U}_{n+1}\) in any step \(n=1,2,\ldots \). So the unknown functions \(u(x,t_{n})\) in any time \(t=t_{n},n=0,1,2,\ldots \) can be found.

4 Error Bounds

Here we give the error analysis of the method presented in the previous section for the Nonlinear Klein-Gordon equation. Suppose that BV be the set of real valued functions \(\mathscr {P}:\mathbb {R}\longrightarrow \mathbb {R }\) with bounded variation on \([-1,1]\). The value \(V(\mathscr {P}(x))\) is defined as total variation of \(\mathscr {P}(x)\) on \([-1\ 1]\). Let for the given weight function \(w(x)=\frac{1}{\sqrt{1-x^{2}}}\), and for \(2\le p<\infty \), we define

$$\begin{aligned} \Vert \mathscr {P}\Vert _{p}:=\left( \int \limits _{-1}^{1}|\mathscr {P} (x)|^{p}w(x)dx\right) ^{\frac{1}{p}}. \end{aligned}$$

Here we need to recall two corollaries from [17].

Corollary 3

Let \(p\ge 2\), \(\mathscr {P}^{(s)} \in BV\) and \(0\le s\le 2^j\) then,

$$\begin{aligned} \parallel \mathscr {P}-L_j\mathscr {P}\parallel _p \le \xi 2^{-j(s+1/p)}V( \mathscr {P}^{(s)}). \end{aligned}$$
(31)

Corollary 4

Let \(p\ge 2\), \(0\le l\le s\) and \(\mathscr {P}^{(s)} \in BV\), then for the interpolatory polynomial based on the zeros of the Jacobi polynomial we have,

$$\begin{aligned} \parallel (\mathscr {P}-L_j\mathscr {P})^{(l)}\parallel _p \le \xi 2^{-j(s+1/p-\mathrm {max}\left\{ l,2l-1/p\right\} )}V(\mathscr {P}^{(s)}). \end{aligned}$$
(32)

In the above corollaries \(\xi \) is constant depends on s.

We consider Eq. (18) as an operator equation in the form

$$\begin{aligned} \mathscr {H}u^{n+1}=\left( (1+\frac{\beta (\delta t)^2}{2})\mathscr {I}+\frac{ \alpha (\delta t)^2}{2}\mathscr {D}\right) u^{n+1}=F, \end{aligned}$$
(33)

where \(\mathscr {I}\) is an identity operator and

$$\begin{aligned} \mathscr {D}= \frac{d^2}{d x^2}, \end{aligned}$$
$$\begin{aligned} F=\left( 2-\frac{\beta (\delta t)^2}{2} \right) u^{n}-\frac{\alpha (\delta t)^2 }{2} u_{xx}^{n}-\gamma (\delta t)^2 (u^n)^k-u^{n-1}+(\delta t)^2 f(x,t_n). \end{aligned}$$

For the operator equation (33) the approximate equation is

$$\begin{aligned} L_{j}\left( \mathscr {H}\right) u_j^{n+1}=L_{j}\left( (1+\frac{\beta (\delta t)^2}{2})\mathscr {I}+\frac{\alpha (\delta t)^2}{2}\mathscr {D} \right) u^{n+1}_j=F_{j}. \end{aligned}$$
(34)

System (34) may be solved numerically to yield an approximate solution equation (1) at each level of time given by the expression \( u^{n+1}_{j}=\mathbf {U}_{n+1}^T\varPhi (x)\). Next Lemma will give the approximation results of the differential operator, and then the total error bound for \(||E^{n+1}_j||_p=|| u^{n+1}-u^{n+1}_j ||_p\) will be presented.

Lemma 5

If \(\left( u^{n+1}\right) ^{(s)}\in BV\), \(s\ge 0\) then for the operator \(\mathscr {D}\) we have

$$\begin{aligned} \Vert \mathscr {D}u^{n+1}-L_{j}\mathscr {D}u^{n+1}\Vert _{p}\le C_1 2^{-j(s+2/p-4)} \Vert V\left( (u^{n+1})^{(s)}\right) \Vert _p. \end{aligned}$$
(35)

Proof

Using (32) by considering \(l=2\) we have

$$\begin{aligned} \Vert \mathscr {D}u^{n+1}-L_{j}\mathscr {D}u^{n+1}\Vert _{p}\le \Vert u^{n+1}_{xx}-L_{j}u^{n+1}_{xx}\Vert _{p} \end{aligned}$$
$$\begin{aligned} \le \Vert (u^{n+1}-L_{j}u^{n+1})_{xx}\Vert _{p} \end{aligned}$$
$$\begin{aligned} \le C_1 2^{-j(s+2/p-4)} V\left( (u^{n+1})^{(s)}\right) . \end{aligned}$$

Theorem 6

If \(u^{n+1}\) and \(u_{j}^{n+1}\) be the exact and approximate solution of (1) at each level of time \(n+1\) respectively, also assume that the operator \(\mathscr {H}=(1+\frac{\beta (\delta t)^{2}}{2}) \mathscr {I}+\frac{\alpha (\delta t)^{2}}{2}\mathscr {D}\) has bounded inverse and \(\left( u^{n+1}\right) ^{(s)},F^{(s)}\in BV\), \(s\ge 0\), then

$$\begin{aligned} ||E_{j}^{n+1}||_{p}\le C\zeta \Vert (L_{j}\mathscr {H})^{-1}\Vert _{p}2^{-j(s+2/p-4)}, \end{aligned}$$

where

$$\begin{aligned} \zeta =\mathrm {max}\left\{ V\left( (u^{n+1})^{(s)}\right) ,V\left( F^{(s)}\right) \right\} , \end{aligned}$$

so for \(s\ge 4\) we ensure the convergence when j goes to the infinity.

Proof

Subtracting Eq. (34) form (1) yields

$$\begin{aligned} -L_{j}\mathscr {H}(u^{n+1}-u_{j}^{n+1})=(\mathscr {H}-L_{j}\mathscr {H} )u^{n+1}-(F-F_{j}), \end{aligned}$$

provided that \(\mathscr {H}^{-1}\) exists and bounded, we obtain the error bound

$$\begin{aligned} \Vert E_{j}^{n+1}\Vert _{p}=\Vert (L_{j}\mathscr {H})^{-1}\Vert _{p}\Vert ( \mathscr {H}-L_{j}\mathscr {H})u^{n+1}-(F-F_{j})\Vert _{p}, \end{aligned}$$
(36)

where \(\Vert (L_{j}\mathscr {H})^{-1}\Vert _{p}=\Vert \left( (1+\frac{\beta (\delta t)^{2}}{2})I+\frac{\alpha (\delta t)^{2}}{2}D_{\phi }^{2}\right) ^{-1}\Vert _{p}.\)

Furthermore, by using Lemma 5 and relation (31), we have

$$\begin{aligned} \Vert (\mathscr {H}-L_{j}\mathscr {H})u^{n+1}\Vert _{p}\le & {} |1+\frac{\beta (\delta t)^{2}}{2}|\Vert (\mathscr {I}-L_{j}\mathscr {I})u^{n+1}\Vert _{p} \end{aligned}$$
(37)
$$\begin{aligned}&+|\frac{\alpha (\delta t)^{2}}{2}|\Vert (\mathscr {D}-L_{j}\mathscr {D} )u^{n+1}\Vert _{p} \end{aligned}$$
(38)
$$\begin{aligned}\le & {} C_{1}|\frac{\alpha (\delta t)^{2}}{2}|2^{-j(s+2/p-4)}V\left( (u^{n+1})^{(s)}\right) \end{aligned}$$
(39)
$$\begin{aligned}&+C_{2}|1+\frac{\beta (\delta t)^{2}}{2}|2^{-j(s+1/p)}V\left( (u^{n+1})^{(s)}\right) , \end{aligned}$$
(40)

and

$$\begin{aligned} \Vert F-F_{j}\Vert _{p}\le C_{3}2^{-j(s+1/p)}V\left( F^{(s)}\right) , \end{aligned}$$
(41)

Substituting Eqs. (40)–(41) in (36), we have

$$\begin{aligned} \Vert u^{n+1}-u_{j}^{n+1}\Vert _{p}\le & {} \Vert (L_{j}\mathscr { H})^{-1}\Vert _{p}\left[ C_{1}|\frac{\alpha (\delta t)^{2}}{2} |2^{-j(s+2/p-4)}V\left( (u^{n+1})^{(s)}\right) \right. \\&\left. +C_{2}|1+\frac{\beta (\delta t)^{2}}{2}|2^{-j(s+1/p)}V\left( (u^{n+1})^{(s)}\right) +C_{3}2^{-j(s+1/p)}V\left( F^{(s)}\right) \right] . \end{aligned}$$

By choosing \(C=max\left\{ C_{1}|\frac{\alpha (\delta t)^{2}}{2}|,C_{2}|1+ \frac{\beta (\delta t)^{2}}{2}|,C_{3}\right\} \) finally we can obtain

$$\begin{aligned} \Vert u^{n+1}-u_{j}^{n+1}\Vert _{p}\le C\zeta \Vert (L_{j}\mathscr {H} )^{-1}\Vert _{p}2^{-j(s+2/p-4)}. \end{aligned}$$

Remark 7

We know that the order of accuracy for the Crank-Nicolson method is \( O(\delta t^{2})\). Therefore total error bound can be represented as

$$\begin{aligned} \Vert u-u_{j}^{n+1}\Vert _{p}\le C\zeta \Vert (L_{j}\mathscr {H})^{-1}\Vert _{p}2^{-j(s+2/p-4)}+O(\delta t^{2}). \end{aligned}$$

5 Numerical Examples

In this section, we give some computational results of numerical experiments with method based on applying the technique discussed in Sect. 3 to find numerical solution of nonlinear Klein-Gordon equation and compare our results with exact solutions and those already available in literature [7, 12]. In order to test the accuracy of the presented method we use the error norms \(L_{2}\), \(L_{\infty }\) and Root-Mean-Square (RMS) through the examples. The numerical computations have been done by the software Matlab.

Example 8

As the first test problem, we consider the nonlinear Klein-Gordon equation (1) with quadratic nonlinearity as

$$\begin{aligned} \frac{\partial ^{2}u}{\partial t^{2}}(x,t)+\alpha \frac{\partial ^{2}u}{ \partial x^{2}}(x,t)+\beta u(x,t)+\gamma u^{2}(x,t)=-x\cos (t)+x^{2}\cos ^{2}(t). \end{aligned}$$

The provided parameters are \(\alpha =-1\), \(\beta =0\) and \(\gamma =1\) in the interval \([-1,1]\) and the initial conditions are given by

$$\begin{aligned} \left\{ \begin{array}{lc} u(x,0)=x, &{} x\in [-1,1], \\ u_{t}(x,0)=0, &{} x\in [-1,1], \end{array} \right. \end{aligned}$$

with the Dirichlet boundary condition

$$\begin{aligned} u(x,t)=h(x,t). \end{aligned}$$
Table 1 \(L_{2}\), \(L_{\infty }\) and RMS errors for \(j=3\) and \(\delta t=0.0001\) compared with [7], Example 1

The analytical solution is given in [7] as \(u(x,t)=x\cos (t).\) The prescribed Dirichlet boundary function h(xt) can be extracted from the exact solution. The \(L_{2}\), \(L_{\infty }\) and RMS errors by applying method discussed in Sect. 3 for \(j=3\), in different times and \(\delta t=0.0001\) are presented in Table 1 and compared with the RBFs method proposed in [7]. As it can be shown from Table 1, our method (PWM) is more accurate than RBFs method while PWM uses much less number of grid points (9 grid points) in comparison with RBFs which uses 100 grid points. Figure 1, shows the graph of errors in the computed solution and approximate solution for \(\delta t=0.0001\) and \(j=3\). The graph of errors in the computed solution for different values of time and \(\delta t=0.0001\), \(j=3\) are plotted in Fig. 2.

Fig. 1
figure 1

Plot of errors (left) and approximate solution (right) with \(\delta t=0.0001\), \(j=3\), example 1

Fig. 2
figure 2

Errors graph for Example 1, with \(j=3\), \( \delta t=0.0001\) and different times

Table 2 \(L_{2}\), \(L_{\infty }\) and RMS errors for \(j=3\) and \(\delta t=0.0001\) compared with [12], Example 2
Fig. 3
figure 3

Errors graph for Example 2, with \(j=3\), \( \delta t=0.0001\) and different times

Example 9

This illustrated example presents the nonlinear Klein-Gordon equation (1) and cubic nonlinearity as

$$\begin{aligned}&\frac{\partial ^{2}u}{\partial t^{2}}(x,t)+\alpha \frac{\partial ^{2}u}{ \partial x^{2}}(x,t)+\beta u(x,t)+\gamma u^{3}(x,t) \\= & {} (x^{2}-2)\cosh (x+t)-4x\sinh (x+t)+x^{6}\cosh ^{3}(x+t). \end{aligned}$$

The provided parameters are \(\alpha =-1\), \(\beta =1\) and \(\gamma =1\) in the interval \([-1,1]\) with the initial conditions are given by

$$\begin{aligned} \left\{ \begin{array}{lc} u(x,0)=x^{2}\cosh (x+t), &{} x\in [-1,1], \\ u_{t}(x,0)=x^{2}\sinh (x+t), &{} x\in [-1,1], \end{array} \right. \end{aligned}$$

with the Dirichlet boundary condition

$$\begin{aligned} u(x,t)=h(x,t). \end{aligned}$$

The analytical solution is given in [7, 12] as \(u(x,t)=x^{2}\cosh (x+t)\). We extract the boundary function h(xt) from the exact solution. The \(L_{2}\), \(L_{\infty }\) and RMS errors by applying method discussed in Sect. 3 for \(j=3\), in different times and \(\delta t=0.0001\) are presented in Table 2 and compared with the Legendre wavelets spectral collocation method (LWSCM) [12]. As it can be seen from Table 2, our method is accurate than LWSCM while PWM uses 9 number of Polynomial wavelet basis functions in comparison with LWSCM which uses 24 number of Legendre wavelet basis. On the other hand, the accuracy of our results remains consistent when the time increases, which is the advantage of using PWM, but in the case of LWSCM the accuracy decreases fastly. Figure 3, shows the graph of errors in the computed solution for different values of time and \(\delta t=0.0001\), \(j=3\). The graph of errors in the computed solution and approximate solution for \(\delta t=0.0001\) and \(j=3\) are plotted in Fig. 4.

Fig. 4
figure 4

Plot of errors (left) and approximate solution (right) with \(\delta t=0.0001\), \(j=3\), example 2

6 Conclusion

A numerical method was employed successfully for the Nonlinear Klein-Gordon equation. This approach is based on the Crank-Nicolson method for temporal discretization and the Wavelet-Collocation method in the spatial direction. After temporal discretization, the operational matrix of derivative along with a collocation method, is used to reduce the considered problem to the corresponding systems of algebraic equations at each time steps. One of the advantages of using polynomial wavelets is that the effort required to implement the method is very low, while the accuracy is high. The convergence analysis is developed. The method is computationally attractive and applications are demonstrated through illustrative examples.