1 Introduction

It is well known that most of the equations arise in the field of mathematics, science, physics, ecology, and engineering are described by partial differential equations (PDEs) and many nonlinear phenomena in solid-state physics, electrostatics, plasma physics, chemical kinetics, and fluid dynamics can also be modeled through PDEs. One example of such a PDE is the nonlinear Klein–Gordon equation which arises in relativistic quantum mechanics and field theory.

Consider the Klein–Gordon equation is of the form:

$$ \frac{{\partial^{2} y}}{{\partial t^{2} }} + \alpha \frac{{\partial^{2} y}}{{\partial x^{2} }} + f\left( y \right) = g\left( {x,t} \right), \quad \forall x \in \left[ {a,b} \right], t > 0. $$
(1.1)

With the initial condition,

$$ y\left( {x,0} \right) = h\left( x \right) $$

Boundary conditions,

$$ y\left( {0,t} \right) = i\left( t \right), y\left( {\beta ,t} \right) = j\left( t \right) $$

where, \( \alpha \) be the constant, \( f\left( y \right) \) be the nonlinearity term, \( y\left( {x,t} \right) \) represents the wave displacement at \( x \) and \( t \). \( h\left( x \right) \) be the wave kinks. The solutions such as nonlinear Klein–Gordon equation are important in many real-life applications. Here are the many mathematicians studied the numerical solution of Klein–Gordon equation they are as follows: Tension spline approach [12], Approximate Solution Using Sobolev Gradients [14], Legendre wavelets methods [19], Numerical solution of the nonlinear Klein/Gordon equation [13], Spline collocation approach [9], Homotopy-perturbation method [1], Polynomial wavelets [11], Radial basis [2], Decomposition method [4] and Differential transform method [8], etc.

Wavelet theory is a recently emerging field and has tremendous applications in image processing, applied mathematics, physics, computer science, and other branches of science. Wavelet is a small wave that oscillates in the small domain and vanishes elsewhere, also, we treat this as a function generated by a small function called mother wavelet. Many researchers developed numerical methods using wavelets as follows, Laguerre wavelets collocation method [17], CAS wavelets analytic solution [18], Hermite wavelets operational matrix method [16], Theoretical study on continuous polynomial wavelet [15], Haar wavelet collocation method [10], Two-dimensional Legendre wavelets [6], etc.

In this article, we have developed a new operational matrix of integration using clique polynomials of the complete graph and applied to solve nonlinear Klein–Gordon equation defined in Eq. (1.1) by transforming PDE to system of nonlinear algebraic equations via properties of clique polynomials that arise in graph theory.

The article is organized as follows, In Sect. 2, defining the clique polynomials and function approximation. Section 3, formulation of a generalized operational matrix of integration by clique polynomials. In Sect. 4, we discussed the clique polynomial method. Section 5, numerical problems are included to demonstrate the usefulness of the present scheme. In the last section, the conclusion is drawn.

2 Clique polynomials and function approximation

Graph theory is one of the gifted subjects in applied mathematics. A graph \( G \) is contained with a nonempty finite set of \( n \) vertices called the vertex set \( V\left( G \right) \), along with a prescribed set of \( m \) unordered pairs of members of \( V\left( G \right) \) called edge set \( E\left( G \right) \). These unordered pairs are joined by a line called an edge. Whenever two vertices share a common edge, then those two edges are coined to be adjacent. If all the vertices and edges present in a graph \( G' \) are from another graph \( G \) then \( G' \) is said to be a subgraph of \( G \). A graph in which all pair of vertices are adjacent is called a complete graph and \( K_{n} \) is the notion for the complete graph on \( n \) vertices. A complete subgraph with \( k \) vertices of a graph \( G \) is called as \( k \)-clique of \( G \). For graph-theoretic definitions, symbols, and related works we refer [3, 5]. Hoede et al. [7] defined clique polynomial of a graph \( G \), denoted by \( C\left( {G; \, x} \right) \), is defined by,

$$ C\left( {G; \, x} \right) = \mathop \sum \limits_{k = 0}^{n} a_{k} x^{k} $$

where \( a_{k} \) is the number of distinct k-cliques in G of size k, with \( a_{0} = 1 \). The clique polynomial of a complete graph \( K_{n} \) with \( n \) vertices is given by,

$$ C\left( {K_{n} ; \, x} \right) = \left( {1 + x} \right)^{n} = \left( {\begin{array}{*{20}c} n \\ 0 \\ \end{array} } \right) + \left( {\begin{array}{*{20}c} n \\ 1 \\ \end{array} } \right)x + \left( {\begin{array}{*{20}c} n \\ 1 \\ \end{array} } \right)x^{2} + \ldots + + \left( {\begin{array}{*{20}c} n \\ 1 \\ \end{array} } \right)x^{n} . $$

In particular,

$$ C\left( {K_{0} ; \, x} \right) = 1, $$
$$ C\left( {K_{1} ; \, x} \right) = 1 + x, $$
$$ C\left( {K_{2} ; \, x} \right) = 1 + 2x + x^{2} . $$

Function approximation

Let \( f\left( x \right) \) be the square-integrable function in the \( R \) then such function approximate by clique polynomials as follows:

$$ f\left( x \right) \approx \mathop \sum \limits_{i = 0}^{n} a_{n} C\left( {K_{i} ; \, x} \right), $$
$$ f\left( x \right) \approx A^{T} C\left( x \right), $$

where, \( A^{T} = \left[ {a_{0} , a_{1} , \ldots ,a_{n} } \right] \) and \( C\left( x \right) = \left[ {C\left( {K_{0} ,x} \right),C\left( {K_{1} ,x} \right),C\left( {K_{2} ,x} \right),C\left( {K_{3} ,x} \right), \ldots ,C\left( {K_{n} ,x} \right)} \right]^{T} , \)

Similarly, if the is \( f \) is a function of two variables, that is \( f = f\left( {x,t} \right) \) then its approximation is,

$$ f\left( {x,t} \right) \approx C\left( t \right)^{T} K C\left( x \right), $$

where,

$$ C\left( t \right)^{T} = \left[ {C\left( {K_{0} ,t} \right),C\left( {K_{1} ,t} \right),C\left( {K_{2} ,t} \right),C\left( {K_{3} ,t} \right), \ldots ,C\left( {K_{n} ,t} \right)} \right], $$
$$ C\left( x \right) = \left[ {C\left( {K_{0} ,x} \right),C\left( {K_{1} ,x} \right),C\left( {K_{2} ,x} \right),C\left( {K_{3} ,x} \right), \ldots ,C\left( {K_{n} ,x} \right)} \right]^{T} , $$

\( K = \left[ {a_{ij} } \right] \) be an \( n \times n \) matrix where \( i = j = 1,2,3, \ldots ,n \)

3 Operational matrix of integration (OMI)

Consider the first six basis of clique polynomials,

$$ C\left( {K_{0} ; \, x} \right) = 1, $$
$$ C\left( {K_{1} ; \, x} \right) = 1 + x, $$
$$ C\left( {K_{2} ; \, x} \right) = 1 + 2x + x^{2} , $$
$$ C\left( {K_{3} ; \, x} \right) = 1 + 3x + 3x^{2} + x^{3} , $$
$$ C\left( {K_{4} ; \, x} \right) = 1 + 4x + 6x^{2} + 4x^{3} + x^{4} , $$
$$ C\left( {K_{5} ; \, x} \right) = 1 + 5x + 10x^{2} 10x^{3} + 5x^{4} + x^{5} , $$

where \( C_{6} \left( x \right) = \left[ {C\left( {K_{0} ; \, x} \right),C\left( {K_{1} ; \, x} \right),C\left( {K_{2} ; \, x} \right),C\left( {K_{3} ; \, x} \right),C\left( {K_{4} ; \, x} \right),C\left( {K_{5} ; \, x} \right)} \right]^{T} . \) Integrating above basis elements concerning to \( x \) from 0 to \( x \) and express in matrix form, we get

$$ \mathop \int \limits_{0}^{x} C\left( {K_{0} ; \, x} \right) dx = x = \left[ {\begin{array}{*{20}c} { - 1} & 1 & 0 & 0 & 0 & 0 \\ \end{array} } \right]C_{6} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} C\left( {K_{1} ; \, x} \right) dx = x + \frac{{x^{2} }}{2} = \left[ {\begin{array}{*{20}c} { - \frac{1}{2}} & 0 & {\frac{1}{2}} & 0 & 0 & 0 \\ \end{array} } \right]C_{6} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} C\left( {K_{2} ; \, x} \right) dx = x + x^{2} + \frac{{x^{3} }}{3} = \left[ {\begin{array}{*{20}c} { - \frac{1}{3}} & 0 & 0 & {\frac{1}{3}} & 0 & 0 \\ \end{array} } \right]C_{6} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} C\left( {K_{3} ; \, x} \right) dx = x + \frac{{3x^{2} }}{2} + x^{3} + \frac{{x^{4} }}{4} = \left[ {\begin{array}{*{20}c} { - \frac{1}{4}} & 0 & 0 & 0 & {\frac{1}{4}} & 0 \\ \end{array} } \right]C_{6} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} C\left( {K_{4} ; \, x} \right) dx = x + 2x^{2} + 2x^{3} + x^{4} + \frac{{x^{5} }}{5} = \left[ {\begin{array}{*{20}c} { - \frac{1}{5}} & 0 & 0 & 0 & 0 & {\frac{1}{5}} \\ \end{array} } \right]C_{6} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} C\left( {K_{5} ; \, x} \right) dx = x + \frac{{5x^{2} }}{2} + \frac{{10x^{3} }}{3} + \frac{{5x^{4} }}{2} + x^{5} + \frac{{x^{6} }}{6} = \left[ {\begin{array}{*{20}c} { - \frac{1}{6}} & 0 & 0 & 0 & 0 & 0 \\ \end{array} } \right]C_{6} \left( x \right) + \frac{1}{6}C\left( {K_{6} ; \, x} \right). $$

Thus,

$$ \mathop \int \limits_{0}^{x} C_{6} \left( x \right) dx = P_{6 \times 6} C_{6} \left( x \right) + \bar{C}_{6} \left( x \right), $$

where,

$$ P_{6 \times 6} = \left[ {\begin{array}{*{20}r} \hfill { - 1} & \hfill 1 & \hfill 0 & \hfill 0 & \hfill 0 & \hfill 0 \\ \hfill { - \frac{1}{2}} & \hfill 0 & \hfill {\frac{1}{2}} & \hfill 0 & \hfill 0 & \hfill 0 \\ \hfill { - \frac{1}{3}} & \hfill 0 & \hfill 0 & \hfill {\frac{1}{3}} & \hfill 0 & \hfill 0 \\ \hfill { - \frac{1}{4}} & \hfill 0 & \hfill 0 & \hfill 0 & \hfill {\frac{1}{4}} & \hfill 0 \\ \hfill { - \frac{1}{5}} & \hfill 0 & \hfill 0 & \hfill 0 & \hfill 0 & \hfill {\frac{1}{5}} \\ \hfill { - \frac{1}{6}} & \hfill 0 & \hfill 0 & \hfill 0 & \hfill 0 & \hfill 0 \\ \end{array} } \right]\quad{\text{and}}\quad\bar{C}_{6} \left( x \right) = \left[ {\begin{array}{*{20}c} 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ {\frac{1}{6}C\left( {K_{6} ; \, x} \right)} \\ \end{array} } \right]. $$

Applying double integration on six basis, we have

$$ \mathop \int \limits_{0}^{x} \mathop \int \limits_{0}^{x} C\left( {K_{0} ; \, x} \right)dxdx = \frac{{x^{2} }}{2} = \left[ {\begin{array}{*{20}c} {\frac{1}{2}} & { - 1} & {\frac{1}{2}} & 0 & 0 & 0 \\ \end{array} } \right]C_{6} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} \mathop \int \limits_{0}^{x} C\left( {K_{1} ; \, x} \right)dxdx = \frac{{x^{2} }}{2} + \frac{{x^{3} }}{6} = \left[ {\begin{array}{*{20}c} {\frac{1}{3}} & { - \frac{1}{2}} & 0 & {\frac{1}{6}} & 0 & 0 \\ \end{array} } \right]C_{6} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} \mathop \int \limits_{0}^{x} C\left( {K_{2} ; \, x} \right)dxdx = \frac{{x^{2} }}{2} + \frac{{x^{3} }}{3} + \frac{{x^{4} }}{12} = \left[ {\begin{array}{*{20}c} {\frac{1}{4}} & { - \frac{1}{3}} & 0 & 0 & {\frac{1}{12}} & 0 \\ \end{array} } \right]C_{6} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} \mathop \int \limits_{0}^{x} C\left( {K_{3} ; \, x} \right)dxdx = \frac{{x^{2} }}{2} + \frac{{x^{3} }}{2} + \frac{{x^{4} }}{4} + \frac{{x^{5} }}{20} = \left[ {\begin{array}{*{20}c} {\frac{1}{5}} & { - \frac{1}{4}} & 0 & 0 & 0 & {\frac{1}{20}} \\ \end{array} } \right]C_{6} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} \mathop \int \limits_{0}^{x} C\left( {K_{4} ; \, x} \right)dxdx = \frac{{x^{2} }}{2} + \frac{{2x^{3} }}{3} + \frac{{x^{4} }}{2} + \frac{{x^{5} }}{5} + \frac{{x^{6} }}{30} = \left[ {\begin{array}{*{20}c} {\frac{1}{6}} & { - \frac{1}{5}} & 0 & 0 & 0 & 0 \\ \end{array} } \right]C_{6} \left( x \right) + \frac{1}{30}C\left( {K_{6} ; \, x} \right), $$
$$ \mathop \int \limits_{0}^{x} \mathop \int \limits_{0}^{x} C\left( {K_{5} ; \, x} \right)dxdx = \frac{{x^{2} }}{2} + \frac{{5x^{3} }}{6} + \frac{{5x^{4} }}{6} + \frac{{x^{5} }}{2} + \frac{{x^{6} }}{6} + \frac{{x^{6} }}{42} = \left[ {\begin{array}{*{20}c} {\frac{1}{7}} & { - \frac{1}{6}} & 0 & 0 & 0 & 0 \\ \end{array} } \right]C_{6} \left( x \right) + \frac{1}{42}C\left( {K_{7} ; \, x} \right), $$

Thus,

$$ \mathop \int \limits_{0}^{x} \mathop \int \limits_{0}^{x} C_{6} \left( x \right) dx = P'_{6 \times 6} C_{6} \left( x \right) + \bar{C}_{6} '\left( x \right), $$

where,

$$ P'_{6 \times 6} = \left[ {\begin{array}{*{20}c} {\frac{1}{2}} & { - 1} & {\frac{1}{2}} & 0 & 0 & 0 \\ {\frac{1}{3}} & { - \frac{1}{2}} & 0 & {\frac{1}{6}} & 0 & 0 \\ {\frac{1}{4}} & { - \frac{1}{3}} & 0 & 0 & {\frac{1}{12}} & 0 \\ {\frac{1}{5}} & { - \frac{1}{4}} & 0 & 0 & 0 & {\frac{1}{20}} \\ {\frac{1}{6}} & { - \frac{1}{5}} & 0 & 0 & 0 & 0 \\ {\frac{1}{7}} & { - \frac{1}{6}} & 0 & 0 & 0 & 0 \\ \end{array} } \right]\quad{\text{and}}\quad\bar{C}_{6} '\left( x \right) = \left[ {\begin{array}{*{20}c} 0 \\ 0 \\ 0 \\ 0 \\ {\frac{1}{30}C\left( {K_{6} ; \, x} \right)} \\ {\frac{1}{42}C\left( {K_{7} ; \, x} \right)} \\ \end{array} } \right]. $$

Now, consider the first seven basis functions are as follows,

$$ C\left( {K_{0} ; \, x} \right) = 1, $$
$$ C\left( {K_{1} ; \, x} \right) = 1 + x, $$
$$ C\left( {K_{2} ; \, x} \right) = 1 + 2x + x^{2} , $$
$$ C\left( {K_{3} ; \, x} \right) = 1 + 3x + 3x^{2} + x^{3} , $$
$$ C\left( {K_{4} ; \, x} \right) = 1 + 4x + 6x^{2} + 4x^{3} + x^{4} , $$
$$ C\left( {K_{5} ; \, x} \right) = 1 + 5x + 10x^{2} + 10x^{3} + 5x^{4} + x^{5} $$
$$ C\left( {K_{6} ; \, x} \right) = 1 + 6x + 15x^{2} + 20x^{3} + 15x^{4} + 6x^{5} + x^{6} $$

where, \( C_{7} \left( x \right) = \left[ {C\left( {K_{0} ; \, x} \right),C\left( {K_{1} ; \, x} \right),C\left( {K_{2} ; \, x} \right),C\left( {K_{3} ; \, x} \right),C\left( {K_{4} ; \, x} \right),C\left( {K_{5} ; \, x} \right),C\left( {K_{6} ; \, x} \right)} \right]^{T} . \) Integrating above basis elements concerning \( x \) from 0 to \( x \) and represent in matrix form, we get

$$ \mathop \int \limits_{0}^{x} C\left( {K_{0} ; \, x} \right) dx = x = \left[ {\begin{array}{*{20}c} { - 1} & 1 & 0 & 0 & 0 & 0 & 0 \\ \end{array} } \right]C_{7} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} C\left( {K_{1} ; \, x} \right) dx = x + \frac{{x^{2} }}{2} = \left[ {\begin{array}{*{20}c} { - \frac{1}{2}} & 0 & {\frac{1}{2}} & 0 & 0 & 0 & 0 \\ \end{array} } \right]C_{7} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} C\left( {K_{2} ; \, x} \right) dx = x + x^{2} + \frac{{x^{3} }}{3} = \left[ {\begin{array}{*{20}c} { - \frac{1}{3}} & 0 & 0 & {\frac{1}{3}} & 0 & 0 & 0 \\ \end{array} } \right]C_{7} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} C\left( {K_{3} ; \, x} \right) dx = x + \frac{{3x^{2} }}{2} + x^{3} + \frac{{x^{4} }}{4} = \left[ {\begin{array}{*{20}c} { - \frac{1}{4}} & 0 & 0 & 0 & {\frac{1}{4}} & 0 & 0 \\ \end{array} } \right]C_{7} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} C\left( {K_{4} ; \, x} \right) dx = x + 2x^{2} + 2x^{3} + x^{4} + \frac{{x^{5} }}{5} = \left[ {\begin{array}{*{20}c} { - \frac{1}{5}} & 0 & 0 & 0 & 0 & {\frac{1}{5}} & 0 \\ \end{array} } \right]C_{7} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} C\left( {K_{5} ; \, x} \right) dx = x + \frac{{5x^{2} }}{2} + \frac{{10x^{3} }}{3} + \frac{{5x^{4} }}{2} + x^{5} + \frac{{x^{6} }}{6} = \left[ {\begin{array}{*{20}c} { - \frac{1}{6}} & 0 & 0 & 0 & 0 & 0 & {\frac{1}{6}} \\ \end{array} } \right]C_{7} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} C\left( {K_{6} ; \, x} \right) dx = x + 3x^{2} + 5x^{3} + 5x^{4} + 3x^{5} + x^{6} + \frac{{x^{7} }}{7} = \left[ {\begin{array}{*{20}c} { - \frac{1}{7}} & 0 & 0 & 0 & 0 & 0 & 0 \\ \end{array} } \right]C_{7} \left( x \right) + \frac{1}{7}C\left( {K_{7} ; \, x} \right), $$

Thus, \( \mathop \int \limits_{0}^{x} C_{7} \left( x \right) dx = P_{7 \times 7} C_{7} \left( x \right) + \;\bar{C}_{7} \left( x \right), \)where,

$$ P_{7 \times 7} = \left[ {\begin{array}{*{20}r} \hfill { - 1} & \hfill 1 & \hfill 0 & \hfill 0 & \hfill 0 & \hfill 0 & \hfill 0 \\ \hfill { - \frac{1}{2}} & \hfill 0 & \hfill {\frac{1}{2}} & \hfill 0 & \hfill 0 & \hfill 0 & \hfill 0 \\ \hfill { - \frac{1}{3}} & \hfill 0 & \hfill 0 & \hfill {\frac{1}{3}} & \hfill 0 & \hfill 0 & \hfill 0 \\ \hfill { - \frac{1}{4}} & \hfill 0 & \hfill 0 & \hfill 0 & \hfill {\frac{1}{4}} & \hfill 0 & \hfill 0 \\ \hfill { - \frac{1}{5}} & \hfill 0 & \hfill 0 & \hfill 0 & \hfill 0 & \hfill {\frac{1}{5}} & \hfill 0 \\ \hfill { - \frac{1}{6}} & \hfill 0 & \hfill 0 & \hfill 0 & \hfill 0 & \hfill 0 & \hfill {\frac{1}{6}} \\ \hfill { - \frac{1}{7}} & \hfill 0 & \hfill 0 & \hfill 0 & \hfill 0 & \hfill 0 & \hfill 0 \\ \end{array} } \right]\quad{\text{and}}\quad\bar{C}_{7} \left( x \right) = \left[ {\begin{array}{*{20}c} 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ {\frac{1}{7}C\left( {K_{7} ; \, x} \right)} \\ \end{array} } \right] $$

Applying double integration on seven basis functions, we have

$$ \mathop \int \limits_{0}^{x} \mathop \int \limits_{0}^{x} C\left( {K_{0} ; \, x} \right)dxdx = \frac{{x^{2} }}{2} = \left[ {\begin{array}{*{20}c} {\frac{1}{2}} & { - 1} & {\frac{1}{2}} & 0 & 0 & 0 & 0 \\ \end{array} } \right]C_{7} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} \mathop \int \limits_{0}^{x} C\left( {K_{1} ; \, x} \right)dxdx = \frac{{x^{2} }}{2} + \frac{{x^{3} }}{6} = \left[ {\begin{array}{*{20}c} {\frac{1}{3}} & { - \frac{1}{2}} & 0 & {\frac{1}{6}} & 0 & 0 & 0 \\ \end{array} } \right]C_{7} \left( x \right), $$
$$ + \frac{{x^{3} }}{3} + \frac{{x^{4} }}{12} = \left[ {\begin{array}{*{20}c} {\frac{1}{4}} & { - \frac{1}{3}} & 0 & 0 & {\frac{1}{12}} & 0 & 0 \\ \end{array} } \right]C_{7} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} \mathop \int \limits_{0}^{x} C\left( {K_{3} ; \, x} \right)dxdx = \frac{{x^{2} }}{2} + \frac{{x^{3} }}{2} + \frac{{x^{4} }}{4} + \frac{{x^{5} }}{20} = \left[ {\begin{array}{*{20}c} {\frac{1}{5}} & { - \frac{1}{4}} & 0 & 0 & 0 & {\frac{1}{20}} & 0 \\ \end{array} } \right]C_{7} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} \mathop \int \limits_{0}^{x} C\left( {K_{4} ; \, x} \right)dxdx = \frac{{x^{2} }}{2} + \frac{{2x^{3} }}{3} + \frac{{x^{4} }}{2} + \frac{{x^{5} }}{5} + \frac{{x^{6} }}{30} = \left[ {\begin{array}{*{20}c} {\frac{1}{6}} & { - \frac{1}{5}} & 0 & 0 & 0 & 0 & {\frac{1}{30}} \\ \end{array} } \right]C_{7} \left( x \right), $$
$$ \mathop \int \limits_{0}^{x} \mathop \int \limits_{0}^{x} C\left( {K_{5} ; \, x} \right)dxdx = \frac{{x^{2} }}{2} + \frac{{5x^{3} }}{6} + \frac{{5x^{4} }}{6} + \frac{{x^{5} }}{2} + \frac{{x^{6} }}{6} + \frac{{x^{6} }}{42} = \left[ {\begin{array}{*{20}c} {\frac{1}{7}} & { - \frac{1}{6}} & 0 & 0 & 0 & 0 & 0 \\ \end{array} } \right]C_{7} \left( x \right) + \frac{1}{42}C\left( {K_{7} ; \, x} \right), $$
$$ \mathop \int \limits_{0}^{x} \mathop \int \limits_{0}^{x} C\left( {K_{6} ; \, x} \right)dxdx = \frac{{x^{2} }}{2} + x^{3} + \frac{{5x^{4} }}{4} + x^{5} + \frac{{x^{6} }}{2} + \frac{{x^{7} }}{7} + \frac{{x^{8} }}{56} = \left[ {\begin{array}{*{20}c} {\frac{1}{8}} & { - \frac{1}{7}} & 0 & 0 & 0 & 0 & 0 \\ \end{array} } \right]C_{7} \left( x \right) + \frac{1}{56}C\left( {K_{8} ; \, x} \right). $$

Thus,

$$ \mathop \int \limits_{0}^{x} \mathop \int \limits_{0}^{x} C_{7} \left( x \right) dx = P'_{7 \times 7} C_{7} \left( x \right) + \bar{C}_{7} '\left( x \right), $$

where,

$$ P'_{7 \times 7} = \left[ {\begin{array}{*{20}c} {\frac{1}{2}} & { - 1} & {\frac{1}{2}} & 0 & 0 & 0 & 0 \\ {\frac{1}{3}} & { - \frac{1}{2}} & 0 & {\frac{1}{6}} & 0 & 0 & 0 \\ {\frac{1}{4}} & { - \frac{1}{3}} & 0 & 0 & {\frac{1}{12}} & 0 & 0 \\ {\frac{1}{5}} & { - \frac{1}{4}} & 0 & 0 & 0 & {\frac{1}{20}} & 0 \\ {\frac{1}{6}} & { - \frac{1}{5}} & 0 & 0 & 0 & 0 & {\frac{1}{30}} \\ {\frac{1}{7}} & { - \frac{1}{6}} & 0 & 0 & 0 & 0 & 0 \\ {\frac{1}{8}} & { - \frac{1}{7}} & 0 & 0 & 0 & 0 & 0 \\ \end{array} } \right]\quad{\text{and}}\quad\bar{C}_{7} '\left( x \right) = \left[ {\begin{array}{*{20}c} 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ {\frac{1}{42}C\left( {K_{7} ; \, x} \right)} \\ {\frac{1}{56}C\left( {K_{8} ; \, x} \right)} \\ \end{array} } \right] $$

Similarly, for the \( n \) basis functions we have generalized the operational matrix of integration as follows:

$$ \mathop \int \limits_{0}^{x} C\left( x \right) dx = P_{n \times n} C\left( x \right) + \bar{C}\left( x \right), $$

where,

$$ P_{n \times n} = \left[ {\begin{array}{*{20}c} { - \frac{1}{{\left( {n - \left( {n - 1} \right)} \right)}}} & {\frac{1}{{\left( {n - \left( {n - 1} \right)} \right)}}} & 0 & 0 & \cdots & 0 \\ { - \frac{1}{{\left( {n - \left( {n - 2} \right)} \right)}}} & 0 & {\frac{1}{{\left( {n - \left( {n - 2} \right)} \right)}}} & 0 & \cdots & 0 \\ { - \frac{1}{{\left( {n - \left( {n - 3} \right)} \right)}}} & 0 & 0 & {\frac{1}{{\left( {n - \left( {n - 3} \right)} \right)}}} & \cdots & 0 \\ \vdots & \vdots & \vdots & \vdots & \ddots & 0 \\ { - \frac{1}{{\left( {n - 1} \right)}}} & 0 & 0 & 0 & \cdots & {\frac{1}{{\left( {n - 1} \right)}}} \\ { - \frac{1}{n}} & 0 & 0 & 0 & \cdots & 0 \\ \end{array} } \right] $$
$$ C\left( x \right) = \left[ {\begin{array}{*{20}c} {C\left( {K_{0} ; \, x} \right)} \\ {C\left( {K_{1} ; \, x} \right)} \\ {C\left( {K_{2} ; \, x} \right)} \\ \vdots \\ {C\left( {K_{n - 1} ; \, x} \right)} \\ \end{array} } \right]\quad{\text{and}}\quad\bar{C}\left( x \right) = \left[ {\begin{array}{*{20}c} 0 \\ 0 \\ 0 \\ \vdots \\ 0 \\ {\frac{1}{n}C\left( {K_{n} ; \, x} \right)} \\ \end{array} } \right]. $$

For double integration with \( n \) basis functions the generalized operational matrix of integration as follows:

$$ \mathop \int \limits_{0}^{x} \mathop \int \limits_{0}^{x} C\left( x \right) dxdx = P^{\prime}_{n \times n} C\left( x \right) + \bar{C^{\prime}}\left( x \right), $$

where,

$$ P'_{n \times n} = \left[ {\begin{array}{*{20}c} {\frac{1}{{\left( {n - \left( {n - 2} \right)} \right)}}} & { - \frac{1}{{\left( {n - \left( {n - 1} \right)} \right)}}} & {\frac{1}{{\left( {n - \left( {n - 2} \right)} \right)\left( {n - \left( {n - 1} \right)} \right)}}} & 0 & \ldots & 0 \\ {\frac{1}{{\left( {n - \left( {n - 3} \right)} \right)}}} & { - \frac{1}{{\left( {n - \left( {n - 2} \right)} \right)}}} & 0 & {\frac{1}{{\left( {n - \left( {n - 3} \right)} \right)\left( {n - \left( {n - 2} \right)} \right)}}} & \ldots & 0 \\ {\frac{1}{{\left( {n - \left( {n - 4} \right)} \right)}}} & { - \frac{1}{{\left( {n - \left( {n - 3} \right)} \right)}}} & 0 & 0 & \ldots & 0 \\ \vdots & \vdots & \vdots & \vdots & \ddots & 0 \\ {\frac{1}{{\left( {n - 1} \right)}}} & { - \frac{1}{{\left( {n - 2} \right)}}} & 0 & 0 & \ldots & {\frac{1}{{\left( {n - 1} \right)\left( {n - 2} \right)}}} \\ {\frac{1}{n}} & { - \frac{1}{{\left( {n - 1} \right)}}} & 0 & 0 & \ldots & 0 \\ {\frac{1}{{\left( {n + 1} \right)}}} & { - \frac{1}{n}} & 0 & 0 & \ldots & 0 \\ \end{array} } \right] $$
$$ C\left( x \right) = \left[ {\begin{array}{*{20}c} {C\left( {K_{0} ; \, x} \right)} \\ {C\left( {K_{1} ; \, x} \right)} \\ {C\left( {K_{2} ; \, x} \right)} \\ \vdots \\ {C\left( {K_{n - 1} ; \, x} \right)} \\ \end{array} } \right]\quad{\text{and}}\quad\bar{C}'\left( x \right) = \left[ {\begin{array}{*{20}c} 0 \\ 0 \\ 0 \\ \vdots \\ 0 \\ {\frac{1}{{n\left( {n - 1} \right)}}C\left( {K_{n} ; \, x} \right)} \\ {\frac{1}{{\left( {n + 1} \right)n}}C\left( {K_{n + 1} ; \, x} \right)} \\ \end{array} } \right]. $$

4 Description of the proposed method

In this section, clique polynomials of complete graphs with the collocation method are used to solve the nonlinear Klein–Gordon equation defined in Eq. (1.1) with different initial-boundary conditions.

Assume that,

$$ \frac{{\partial^{3} y\left( {x,t} \right)}}{{\partial x^{2} \partial t}} = C\left( t \right)^{T} K C\left( x \right), $$
(4.1)

where,

$$ C\left( t \right)^{T} = \left[ {C\left( {K_{0} ,t} \right),C\left( {K_{1} ,t} \right),C\left( {K_{2} ,t} \right),C\left( {K_{3} ,t} \right), \ldots ,C\left( {K_{n} ,t} \right)} \right], $$
$$ C\left( x \right) = \left[ {C\left( {K_{0} ,x} \right),C\left( {K_{1} ,x} \right),C\left( {K_{2} ,x} \right),C\left( {K_{3} ,x} \right), \ldots ,C\left( {K_{n} ,x} \right)} \right]^{T} $$

\( K = \left[ {a_{ij} } \right] \) be an \( n \times n \) matrix where \( i = j = 1,2,3, \ldots ,n \).

Now, integrate Eq. (4.1) concerning \( t \) from 0 to \( t \), we get

$$ \begin{aligned} \frac{{\partial^{2} y\left( {x,t} \right)}}{{\partial x^{2} }} = \frac{{\partial^{2} y\left( {x,0} \right)}}{{\partial x^{2} }} + \mathop \int \limits_{0}^{t} C\left( t \right)^{T} K C\left( x \right)dt, \hfill \\ \frac{{\partial^{2} y\left( {x,t} \right)}}{{\partial x^{2} }} = \frac{{\partial^{2} y\left( {x,0} \right)}}{{\partial x^{2} }} + \left[ {P_{n \times n} C\left( t \right) + \bar{C}\left( t \right)} \right]^{T} K C\left( x \right), \hfill \\ \end{aligned} $$
(4.2)

Integrating Eq. (4.2) concerning \( x \) from 0 to \( x \),

$$ \begin{aligned} \frac{{\partial y\left( {x,t} \right)}}{\partial x} = \frac{{\partial y\left( {0,t} \right)}}{\partial x} + \frac{{\partial y\left( {x,0} \right)}}{\partial x} - \frac{{\partial y\left( {0,0} \right)}}{\partial x} + \mathop \int \limits_{0}^{x} \left[ {P_{n \times n} C\left( t \right) + \bar{C}\left( t \right)} \right]^{T} K C\left( x \right)dx, \hfill \\ \frac{{\partial y\left( {x,t} \right)}}{\partial x} = \frac{{\partial y\left( {0,t} \right)}}{\partial x} + \frac{{\partial y\left( {x,0} \right)}}{\partial x} - \frac{{\partial y\left( {0,0} \right)}}{\partial x} + \left[ {P_{n \times n} C\left( t \right) + \bar{C}\left( t \right)} \right]^{T} K\left[ {P_{n \times n} C\left( x \right) + \bar{C}\left( x \right)} \right], \hfill \\ \end{aligned} $$
(4.3)

Integrating Eq. (4.3) concerning \( x \) from 0 to \( x \),

$$ \begin{aligned} y\left( {x,t} \right) = y\left( {0,t} \right) + y\left( {x,0} \right) - y\left( {0,0} \right) + x\left[ {\frac{{\partial y\left( {0,t} \right)}}{\partial x} - \frac{{\partial y\left( {0,0} \right)}}{\partial x}} \right] + \mathop \int \limits_{0}^{x} \left[ {\left[ {P_{n \times n} C\left( t \right) + \bar{C}\left( t \right)} \right]^{T} K\left[ {P_{n \times n} C\left( x \right) + \bar{C}\left( x \right)} \right]} \right]dx, \hfill \\ y\left( {x,t} \right) = y\left( {0,t} \right) + y\left( {x,0} \right) - y\left( {0,0} \right) + x\left[ {\frac{{\partial y\left( {0,t} \right)}}{\partial x} - \frac{{\partial y\left( {0,0} \right)}}{\partial x}} \right] + \left[ {P_{n \times n} C\left( t \right) + \bar{C}\left( t \right)} \right]^{T} K\left[ {P^{\prime}_{n \times n} C\left( x \right) + \bar{C^{\prime}}\left( x \right)} \right], \hfill \\ \end{aligned} $$
(4.4)

Put \( x = \beta \) in the above equation,

$$ y\left( {\beta ,t} \right) = \, y\left( {0,t} \right) + y\left( {\beta ,0} \right) - y\left( {0,0} \right) + \beta \left[ {\frac{{\partial y\left( {0,t} \right)}}{\partial x} - \frac{{\partial y\left( {0,0} \right)}}{\partial x}} \right] + \left[ {P_{n \times n} C\left( t \right) + \bar{C}\left( t \right)} \right]^{T} K\left[ {P^{\prime}_{n \times n} C\left( x \right) + \bar{C^{\prime}}\left( x \right)} \right]|_{x = \beta } , $$
$$ \left[ {\frac{{\partial y\left( {0,t} \right)}}{\partial x} - \frac{{\partial y\left( {0,0} \right)}}{\partial x}} \right] = \, \frac{1}{\beta }\left[ {y\left( {\beta ,t} \right) - y\left( {0,t} \right) - y\left( {\beta ,0} \right) + y\left( {0,0} \right)} \right] - \left[ {P_{n \times n} C\left( t \right) + \bar{C}\left( t \right)} \right]^{T} K\left[ {P^{\prime}_{n \times n} C\left( x \right) + \bar{C^{\prime}}\left( x \right)} \right]|_{x = \beta } , $$
(4.5)

Substitute Eq. (4.5) in (4.4) we get,

$$ y\left( {x,t} \right) = \, y\left( {0,t} \right) + y\left( {x,0} \right) - y\left( {0,0} \right) + x\left[ {\frac{1}{\beta }\left[ {y\left( {\beta ,t} \right) - y\left( {0,t} \right) - y\left( {\beta ,0} \right) + y\left( {0,0} \right)} \right] - \left[ {P_{n \times n} C\left( t \right) + \bar{C}\left( t \right)} \right]^{T} K\left[ {P^{\prime}_{n \times n} C\left( x \right) + \bar{C^{\prime}}\left( x \right)} \right]|_{x = \beta } .} \right]\left[ {P_{n \times n} C\left( t \right) + \bar{C}\left( t \right)} \right]^{T} K\left[ {P^{\prime}_{n \times n} C\left( x \right) + \bar{C^{\prime}}\left( x \right)} \right] $$
(4.6)

Differentiating Eq. (4.6) twice concerning \( t \), we get

$$ \frac{{\partial y\left( {x,t} \right)}}{\partial t} = \frac{{\partial y\left( {0,t} \right)}}{\partial t} + x\frac{d}{dt}\left[ {\frac{1}{\beta }\left[ {y\left( {\beta ,t} \right) - y\left( {0,t} \right)} \right] - \left[ {P_{n \times n} C\left( t \right) + \bar{C}\left( t \right)} \right]^{T} K\left[ {P^{\prime}_{n \times n} C\left( x \right) + \bar{C^{\prime}}\left( x \right)} \right]|_{x = \beta } .} \right] + \frac{d}{dt}\left[ {P_{n \times n} C\left( t \right) + \bar{C}\left( t \right)} \right]^{T} K\left[ {P^{\prime}_{n \times n} C\left( x \right) + \bar{C^{\prime}}\left( x \right)} \right], $$
(4.7)
$$ \frac{{\partial^{2} y\left( {x,t} \right)}}{{\partial t^{2} }} = \frac{{\partial^{2} y\left( {0,t} \right)}}{{\partial t^{2} }} + x\frac{{d^{2} }}{{dt^{2} }}\left[ {\frac{1}{\beta }\left[ {y\left( {\beta ,t} \right) - y\left( {0,t} \right)} \right] - \left[ {P_{n \times n} C\left( t \right) + \bar{C}\left( t \right)} \right]^{T} K\left[ {P^{\prime}_{n \times n} C\left( x \right) + \bar{C^{\prime}}\left( x \right)} \right]|_{x = \beta } .} \right] + \frac{{d^{2} }}{{dt^{2} }}\left[ {P_{n \times n} C\left( t \right) + \bar{C}\left( t \right)} \right]^{T} K\left[ {P^{\prime}_{n \times n} C\left( x \right) + \bar{C^{\prime}}\left( x \right)} \right], $$
(4.8)

Substitute Eqs. (4.8) (4.6), and (4.2) in Eq. (1.1) we get,

$$ \begin{aligned} & \left[ {\frac{{\partial^{2} y\left( {0,t} \right)}}{{\partial t^{2} }} + x\frac{{d^{2} }}{{dt^{2} }}\left[ {\frac{1}{\beta }\left[ {y\left( {\beta ,t} \right) - y\left( {0,t} \right)} \right] - \left[ {P_{n \times n} C\left( t \right) + \bar{C}\left( t \right)} \right]^{T} K\left[ {P^{\prime}_{n \times n} C\left( x \right) + \bar{C^{\prime}}\left( x \right)} \right]|_{x = \beta } .} \right] + \frac{{d^{2} }}{{dt^{2} }}\left[ {P_{n \times n} C\left( t \right) + \bar{C}\left( t \right)} \right]^{T} K\left[ {P^{\prime}_{n \times n} C\left( x \right) + \bar{C^{\prime}}\left( x \right)} \right]} \right] \hfill \\ &\quad + f\left( {y\left( {0,t} \right) + y\left( {x,0} \right) - y\left( {0,0} \right) + x\left[ {\frac{1}{\beta }\left[ {y\left( {\beta ,t} \right) - y\left( {0,t} \right) - y\left( {\beta ,0} \right) + y\left( {0,0} \right)} \right] - \left[ {P_{n \times n} C\left( t \right) + \bar{C}\left( t \right)} \right]^{T} K\left[ {P^{\prime}_{n \times n} C\left( x \right) + \bar{C^{\prime}}\left( x \right)} \right]|_{x = \beta } } \right] + \left[ {P_{n \times n} C\left( t \right) + \bar{C}\left( t \right)} \right]^{T} K\left[ {P^{\prime}_{n \times n} C\left( x \right) + \bar{C^{\prime}}\left( x \right)} \right]} \right) \hfill \\ & \quad + \alpha \left[ {\frac{{\partial^{2} y\left( {x,0} \right)}}{{\partial x^{2} }} + \left[ {P_{n \times n} C\left( t \right) + \bar{C}\left( t \right)} \right]^{T} K C\left( x \right)} \right] = g\left( {x,t} \right), \hfill \\ \end{aligned} $$

Collocate the above equation by the following collocation points \( x_{i} = t_{i} = \frac{2i - 1}{{2n^{2} }}, i = 1,2, \ldots ,n^{2} \), then solve this system of nonlinear equations by suitable solvers yields clique polynomial coefficients. On substituting these coefficients in Eq. (4.6) we get numerical solution of Eq. (1.1).

5 Numerical applications

Example 1

Consider the Klein–Gordon equation [12]

$$ \frac{{\partial^{2} y}}{{\partial t^{2} }} - \frac{{\partial^{2} y}}{{\partial x^{2} }} + \frac{{\pi^{2} }}{4}y + y^{2} = x^{2} sin^{2} \left[ {\frac{\pi t}{2}} \right] = 0,\quad \forall x \in \left( { - 1,1} \right), t > 0. $$

with the initial condition,

$$ y\left( {x,0} \right) = 0, $$

boundary conditions,

$$ y\left( { - 1,t} \right) = - sin\left[ {\frac{\pi t}{2}} \right], y\left( {1,t} \right) = sin\left[ {\frac{\pi t}{2}} \right]. $$

The exact solution is \( y\left( {x,t} \right) = xsin\left[ {\frac{\pi t}{2}} \right]. \) On solving this equation by clique polynomial method. Figure 1 represents a time–space graph of the solution at different values of \( n \) (size of the matrix) and it reveals that accuracy in the solution directly proportional to \( n. \) Figs. 2 and 3 shows a graphical comparison of exact and numerical solution at different values of \( t \) and \( x \). Table 1 shows the comparison of \( L_{\infty } \)-error, \( L_{2} \)-error, and RMS-error of the proposed method with other techniques in the literature.

Fig. 1
figure 1

Time-space graph of solution at different values of \( n \) for Example 1

Fig. 2
figure 2

Numerical comparison of solution at different values of \( x \) with Exact solution for Example 1

Fig. 3
figure 3

Numerical comparison of solution at different values of \( t \) with Exact solution for Example 1

Table 1 Error comparison of solutions for Example 1

Example 2

Consider the nonlinear Klein–Gordon equation [12]

$$ \frac{{\partial^{2} y}}{{\partial t^{2} }} - \frac{{\partial^{2} y}}{{\partial x^{2} }} + y^{2} = 0, \quad \forall x \in \left( {0,1} \right), t > 0. $$

With the initial condition,

$$ y\left( {x,0} \right) = 1 + { \sin }\left( x \right) $$

Boundary conditions,

$$ y\left( {0,t} \right) = 1 - \frac{{t^{2} }}{2}, y\left( {1,t} \right) = \frac{221}{120} - \frac{305}{144}t^{2} + \frac{103}{144}t^{4} . $$

This problem has no exact solution \( . \) On solving this equation by clique polynomial method. Figure 4 represents a time–space graph of the solution by the present technique at \( n = 10 \). Table 2 shows the comparison of the proposed method solution with other techniques in the literature. We solved this problem by Matlab 2017 with CPU time is 15.74 s.

Fig. 4
figure 4

Time-space graph of solution at \( n = 10 \) for Example 2

Table 2 Numerical comparison of solutions for Example 2 at \( n = 10 \) and \( t = 0.1 \) with other methods

Example 3

Consider the nonlinear Klein–Gordon equation [12]

$$ \frac{{\partial^{2} y}}{{\partial t^{2} }} - a^{2} \frac{{\partial^{2} y}}{{\partial x^{2} }} + ay - by^{3} = 0, \forall x \in \left( { - 1,1} \right), t > 0. $$

The case I: kick wave solution, with the initial condition,

$$ y\left( {x,0} \right) = \sqrt {\frac{a}{b}} tanh\left[ {\sqrt {\frac{a}{{2\left( {c^{2} - a^{2} } \right)}}} x} \right] $$

Boundary conditions,

$$ y\left( { - 1,t} \right) = \sqrt {\frac{a}{b}} tanh\left[ {\sqrt {\frac{a}{{2\left( {c^{2} - a^{2} } \right)}}} \left( { - 1 - ct} \right)} \right], y\left( {1,t} \right) = \sqrt {\frac{a}{b}} tanh\left[ {\sqrt {\frac{a}{{2\left( {c^{2} - a^{2} } \right)}}} \left( {1 - ct} \right)} \right]. $$

The exact kick wave solution is \( y\left( {x,t} \right) = \sqrt {\frac{a}{b}} tanh\left[ {\sqrt {\frac{a}{{2\left( {c^{2} - a^{2} } \right)}}} \left( {x - ct} \right)} \right]. \) On solving this equation by clique polynomial method. Figure 5 represents a time- space graph of the solution at different values of \( n \) and its error. Table 3 shows the \( L_{\infty } \)-error, \( L_{2} \)-error, and RMS-error of the proposed method. Figures 6 and 7 show a graphical comparison of exact and numerical solutions at different values of \( t \) and \( x \). We solved this problem by Matlab 2017 with CPU time is 10.86 s.

Fig. 5
figure 5

Time-space graph of solution at different values of \( n \) for Example 3 case I at \( a = 0.1, b = 1, c = 0.3 \)

Table 3 Error by present method for Example 3 case I
Fig. 6
figure 6

Numerical comparison of solution at different values of \( t \) with Exact solution for Example 3 case I

Fig. 7
figure 7

Numerical comparison of solution at different values of \( x \) with Exact solution for Example 3 case I

Case II: Soliton wave solution,

with the initial condition,

$$ y\left( {x,0} \right) = \sqrt {\frac{2a}{b}} sech\left[ {\sqrt {\frac{a}{{\left( {a^{2} - c^{2} } \right)}}} x} \right] $$

Boundary conditions,

$$ y\left( { - 1,t} \right) = \sqrt {\frac{2a}{b}} sech\left[ {\sqrt {\frac{a}{{\left( {a^{2} - c^{2} } \right)}}} \left( { - 1 - ct} \right)} \right], y\left( {1,t} \right) = \sqrt {\frac{2a}{b}} sech\left[ {\sqrt {\frac{a}{{\left( {a^{2} - c^{2} } \right)}}} \left( {1 - ct} \right)} \right]. $$

The exact soliton wave solution is \( y\left( {x,t} \right) = \sqrt {\frac{2a}{b}} sech\left[ {\sqrt {\frac{a}{{\left( {a^{2} - c^{2} } \right)}}} \left( {x - ct} \right)} \right]. \) On solving this equation by clique polynomial method. Figure 8 represents a time- space graph of the solution at different values of \( n \) and its error. Table 4 shows the \( L_{\infty } \)-error, \( L_{2} \)-error, and RMS-error of the proposed method. Figures 6 and 7 show a graphical comparison of exact and numerical solutions at different values of \( t \) and \( x \). We solved this problem by Matlab 2017 with CPU time is 13.04 s (Figs. 9, 10).

Fig. 8
figure 8

Time-space graph of solution at different values of \( n \) for Example 3 case II at \( a = 0.3, b = 1,\; c = 0.25 \)

Table 4 Error comparison of solutions by Present Method for Example 3 case II
Fig. 9
figure 9

Numerical comparison of solution at different values of \( t \) with Exact solution for Example 3 case II

Fig. 10
figure 10

Numerical comparison of solution at different values of \( x \) with Exact solution for Example 3 case II

Example 4

Consider the nonlinear Klein–Gordon equation [12]

$$ \frac{{\partial^{2} y}}{{\partial t^{2} }} - \frac{{\partial^{2} y}}{{\partial x^{2} }} + y + y^{3} = \left( {x^{2} - 2} \right)\cosh \left( {x + t} \right) - 4xsinh\left( {x + t} \right) + x^{6} cosh^{3} \left( {x + t} \right), \forall x \in \left( { - 1,1} \right), t > 0. $$

With the initial condition,

$$ y\left( {x,0} \right) = x^{2} { \cosh }\left( x \right) $$

Boundary conditions,

$$ y\left( { - 1,t} \right) = x^{2} { \cosh }\left( { - 1 + t} \right), \quad y\left( {1,t} \right) = x^{2} { \cosh }\left( {1 + t} \right). $$

The exact solution is \( y\left( {x,t} \right) = x^{2} { \cosh }\left( {x + t} \right). \) On solving this equation by the proposed method. Figure 11 represents the time- space graph of the solution at different values of \( n \) and its error. Table 5 shows the comparison of \( L_{\infty } \)-error, \( L_{2} \)-error, and RMS-error of the proposed method with other techniques in the literature. We solved this problem by Matlab 2017 with CPU time is 18.16 s.

Fig. 11
figure 11

Time-space graph of solution at different values of \( n \) for Example 4

Table 5 Error comparison of solutions for Example 4

6 Conclusion

In this article, we constructed an operational matrix of integration using clique polynomials and generated a new method (clique polynomial method) for the special type of one-dimensional Partial differential equation such as Klein–Gordon equation. We solved four nonlinear equations and discussed the accuracy of the proposed scheme in Tables 1, 2, 3 by comparing \( {\text{L}}_{\infty } \)-error, \( {\text{L}}_{2} \)-error, and RMS-error with the other methods in the literature. These computational results show that our proposed algorithm is effective and accurate in comparison with existing methods. Table 1 says that proposed method consumes less CPU time than Method I and Method in the literature.