1 Introduction

The presence of nonzero anisotropy, in which the radial pressure differs from the tangential pressure, is an important component in modelling relativistic stellar systems in the absence of an electric field. The pioneering paper by Bowers and Liang [1] introduced anisotropic spheres in general relativity. Subsequently there has been extensive research in studying the physics related to anisotropic pressures. It was shown by Dev and Gleiser [2, 3] that pressure anisotropy influences the mass, structure and physical properties of highly compact spheres. It is important to observe that the mass of the object and the redshift both change with different values of the magnitude of the anisotropy. In recent times there has been made a considerable effort in modelling observed astrophysical objects in the presence of anisotropy. Some recent research papers addressing this physical feature include the work of Sharma and Ratanpal [4], Ngubelanga et al. [5, 6], Sunzu et al. [7, 8], Murad and Fatema [9, 10] and Murad [11], and the references therein. The physical analyses contained in these treatments confirm the importance of including nonzero anisotropy in modelling astrophysical objects. It should be noted that the presence of anisotropic pressures leads to values of observed compactness parameters for several astrophysical bodies including Her X-1, PSR 0943+10, 4U 1820-30, SAX J 1808.4-3658, and 4U 1728-34. It is therefore important to generate analytical models of the Einstein field equations, with a matter tensor containing anisotropy, which are consistent with physical requirements for astrophysical applications.

To generate a physically consistent model we need to find an analytical solution of the general relativistic field equations. This is achieved by restricting the spacetime geometry, the matter content or specifying an equation of state. A rather different approach is to use the embedding of a four-dimensional differentiable manifold into a higher dimensional Euclidean space. Embedding of curved spacetimes into spacetimes of higher flat dimensions has assisted in generating several new exact models in cosmology and relativistic astrophysics [12]. The embedding condition gives an additional differential equation, the so-called Karmarkar condition [13], in static spherical spacetimes relating the two gravitational potentials. A solution of the Karmarkar condition then helps to solve the Einstein field equations. This method has proved to be a fruitful mechanism to find new relativistic astrophysical models in recent investigations. Bhar et al. [14,15,16], Maurya et al. [17,18,19,20] and Newton Singh et al. [21,22,23] have generated different families of physically acceptable Karmarkar spacetimes that describe the interior regions of acceptable stars. In these analyses a particular form of one of the potentials is made, which solves the Karmarkar condition, giving the second potential, eventually leading to an astrophysical model. In our treatment we show that a very general form of the chosen potential, including hyperbolic functions, leads to an astrophysical model with desirable physical features. This shows that the Karmarkar condition allows for more complicated (and acceptable) physical behaviour than the earlier simpler forms used for the gravitational potentials.

In this paper we present a new interior anisotropic model for astrophysical compact stars by solving the embedding condition in static spherical spacetimes. We show that the resulting exact solutions can be used to describe a physically reasonable astrophysical matter distribution. The exterior region is characterized by the Schwarzschild vacuum metric. We discuss the Einstein field equations in Sect. 2 and present the Karmakar embedding condition. In Sect. 3, we generate an exact solution to the embedding condition and show how this leads to an exact solution of the field equations. In Sect. 4 we present the matching conditions between interior and exterior spacetimes regions; we also demonstrate that the parameters arising are bounded. A detailed physical analysis is undertaken in Sect. 5. In particular the stability, cracking and energy conditions of the relativistic sphere are studied. We also investigate the physical features of the model in connection with the objects LMC X-4, EXO 1785-248, PSR J1903+327 and 4U 1820-30; the results are presented in the form of tables and graphs. We discuss the significance of the results obtained in this paper in Sect. 6.

2 Field equations and the Karmarkar condition

We assume that the interior matter of the star is locally anisotropic which is given by the following line element (by taking \(c=1\))

$$\begin{aligned} \mathrm{d}s^{2} =-e^{\lambda (r) } \mathrm{d}r^{2} -r^{2} (\mathrm{d}\theta ^{2} +\sin ^{2} \theta \, \mathrm{d}\phi ^{2} )+e^{\nu (r) } \, \mathrm{d}t^{2} , \end{aligned}$$
(1)

where \(e^{\lambda (r)}\) and \(e^{\nu (r)}\) represent the gravitational potentials of stellar structure. The Einstein field equations corresponding to an anisotropic fluid distribution is given by (assume \(G=c=1\))

$$\begin{aligned} -8\pi \,T^{i}_{j}= R^{i}_{j}-\frac{1}{2}\,R\,g^{i}_{j}, \end{aligned}$$
(2)

where \(T^{i}_{j}\) and \(R^i_j\) represent the energy-momentum tensor and contracted Ricci tensor, respectively, while R is the scalar curvature tensor. The energy tensor for the anisotropic matter distribution can be defined as

$$\begin{aligned} T^{i}_{j}=(\rho +p_t)\,v^i\,v_j-p_t\,g^i_j+(p_r-p_t)\,u^i\,u_j , \end{aligned}$$
(3)

where the contravariant quantity \(v^i\) is the four-velocity vector and \(u^i\) is the unit spacelike vector in the radial direction. Here \(p_r\), \(p_t\) and \(\rho \) denote the radial pressure, tangential pressure and matter density for anisotropic matter.

In view of line element (1), the Einstein field equations (2) provide the following differential equations for the anisotropic star:

$$\begin{aligned} \rho= & {} \frac{e^{-\lambda }}{8\pi }\left[ \frac{r\,\lambda '+e^{\lambda }-1 }{r^{2}}\right] , \end{aligned}$$
(4)
$$\begin{aligned} p_{r}= & {} \frac{e^{-\lambda }}{8\pi }\left[ \frac{r\,v'-e^{\lambda }+1}{r^{2}} \right] , \end{aligned}$$
(5)
$$\begin{aligned} p_{t}= & {} \frac{e^{-\lambda }}{8\pi }\left[ \frac{2r\,v''-r\,\lambda 'v'+r\,v'^{2} +2\,v'-2\,\lambda '}{4r^2} \right] . \end{aligned}$$
(6)

Here primes denote the derivative with respect to the radial coordinate r. The value of the velocity of light (c) and the gravitational constant (G) are taken to be unity in the above coupled differential equations. Furthermore we obtain the anisotropic factor by using the pressure isotropy condition with Eqs. (5) and (6) as

$$\begin{aligned} \Delta= & {} \,p_{t} -\, p_{r} \!=\!\frac{e^{-\lambda }}{8\pi }\left[ \frac{2r\,v''-r\,\lambda 'v'\!+\! r\,v'^{2}-2v'-2\lambda '}{4r}\right] \nonumber \\&-\frac{e^{-\lambda }-1}{r^{2}}. \end{aligned}$$
(7)

2.1 Karmarkar condition

It is well known that the spherical symmetric line element (1) can always be embedded in six dimensional flat spacetime which implies that the spherical symmetric line element is of embedding class two in general. On the other hand we can also embed the spherical line element into five dimensional flat spacetime if it satisfies the Karmarkar condition [13]. Then it represents the spacetime of embedding class one. However, it is a necessary and sufficient condition for the spherically symmetric spacetime to be of class one. The Karmarkar condition is given in terms of the curvature components by

$$\begin{aligned} \mathfrak {R}_{1414}=\frac{\mathfrak {R}_{1212}\,\mathfrak {R}_{3434}+\mathfrak {R}_{1224}\,\mathfrak {R}_{1334}}{\mathfrak {R}_{2323}}, \end{aligned}$$
(8)

with \(\mathfrak {R}_{2323}\ne 0\)   [24]. The nonzero components of the Riemann curvature tensor \(\mathfrak {R}_{hijk}\) for the metric (1) are given by

$$\begin{aligned} \mathfrak {R}_{2323}= & {} \frac{\sin ^2\theta \,(e^{\lambda }-1)\,r^2}{e^{\lambda }}, \,\, \mathfrak {R}_{1212}=\frac{\lambda '\,r}{2},\,\, \\ \mathfrak {R}_{2424}= & {} \frac{\nu '\,r\,e^{\nu -\lambda }}{2},\,\, \mathfrak {R}_{1224}=0,\,\,\\ \mathfrak {R}_{1414}= & {} \frac{e^\nu }{4}\,[2\,\nu ''+\nu '^2-\lambda '\,\nu '],\,\, \mathfrak {R}_{3434}=\sin ^2{\theta }\,\mathfrak {R}_{2424}. \end{aligned}$$

By plugging these components of \(\mathfrak {R}_{hijk}\) in Eq. (8) we get the following differential equation:

$$\begin{aligned} \frac{\nu ''}{\nu '}+\frac{\nu '}{2}=\frac{\lambda '\,e^{\lambda }}{2\,(e^{\lambda }-1)}. \end{aligned}$$
(9)

On solving the differential equation (9) we obtain the potential,

$$\begin{aligned} e^{\nu }=\left[ C+D\int {\sqrt{(e^{\lambda (r)}-1)}\mathrm{d}r}\right] ^2, \end{aligned}$$
(10)

where C and D are nonzero arbitrary constants of integration.

2.2 Tolman–Oppenheimer–Volkoff equation

Now to derive the Tolman–Oppenheimer–Volkoff (TOV) equation we evaluate \(p_r+\rho \) from Eqs. (4) and (5) to get

$$\begin{aligned} \rho +p_r= \frac{(\lambda '+\nu ')\,e^{-\lambda }}{8\,\pi \,r}. \end{aligned}$$
(11)

The derivative of the radial pressure is

$$\begin{aligned} \frac{\mathrm{d}p_r}{\mathrm{d}r}=\left[ \frac{r\,\nu ''-r\,\nu '\,\lambda '-\nu '-\lambda '}{8\,\pi \,r^2}\right] \,e^{-\lambda }+\frac{2(1-e^{-\lambda })}{8\,\pi \,r^3}.\nonumber \\ \end{aligned}$$
(12)

Then using Eqs. (7), (11) and (12) we get

$$\begin{aligned} \frac{2}{r}(p_t-p_r)-\frac{\mathrm{d}p_r}{\mathrm{d}r}-\frac{1}{2}\,\nu '\,(\rho +p_r)=0. \end{aligned}$$
(13)

If the gravitational mass within a compact star of radius r is denoted \(M_G(r)\), then it is given by the Tolman–Whittaker formula [25]:

$$\begin{aligned} M_G(r)=\frac{1}{2}r^2e^{\frac{\nu -\lambda }{2}\nu '}. \, \end{aligned}$$
(14)

Then from Eqs. (13) and (14), we obtain

$$\begin{aligned} \frac{2}{r}(p_t-p_r)=\frac{\mathrm{d}p_r}{\mathrm{d}r}+\frac{M_G(r)\,(\rho +p_r)}{r^2}\,e^{\lambda -\nu }. \end{aligned}$$
(15)

The above equation (15) represents the well known generalized Tolman–Oppenheimer–Volkoff (TOV) equation which provides the equilibrium condition for anisotropic stellar matter distribution.

3 Anisotropic solution of embedding class one

Equations (4)–(5) have five unknowns, namely \(\nu \), \(\lambda \), \(\rho \), \(p_r\) and \(p_t\). However, the Karmarkar condition provides a relation between \(\nu \) and \(\lambda \), which implies that we have four conditions (including three equations) to solve this system of equations. For this paper we consider a totally new expression for gravitational potential \(e^{\lambda }\), which has not been used before. We take

$$\begin{aligned} e^{\lambda }=\frac{1+2cr^2+\cosh [2(ar^2+b)]}{1+\cosh [2(ar^2+b)]}, \end{aligned}$$
(16)

where a, b and c are nonzero constants, The units of the constants a and c are \(length^{-2}\). We need to check whether the given expression for \(\lambda \) is physically valid. For this purpose we obtain \(e^{\lambda }\) at the centre and plot Fig. 1. We observe that it is increasing monotonically away from the centre and \(e^{\lambda }=1\) at the centre. This behaviour of \(e^{\lambda }\) indicates that it is physically acceptable.

By plugging the value of \(\lambda \) into Eq. (10), we obtain

$$\begin{aligned} e^{\nu }=A^2\left[ B+\tan ^{-1}\sinh (ar^2+b)\right] ^2, \end{aligned}$$
(17)

where \(A=D\,\frac{\sqrt{c}}{2\,a}\) and \(B=\frac{2\,a\,C}{\sqrt{c}\,D}.\) The function \(e^{\nu }=A^2\,[B+\tan ^{-1}\sinh \,b]^2\) is finite and positive at the centre. Also we may observe from Fig. 1 that the gravitational potential \(e^{\nu }\) is increasing with r throughout the star. This implies that the above expression of \(\nu \) may be suitable to obtain a physically valid anisotropic solution according to Lake [26].

Fig. 1
figure 1

Behaviour of gravitational potential \(e^{\nu }\) (left panel) and \(e^{\lambda }\) (right panel) vs. fractional radius r / R for LMC X-4, EXO 1785-248, PSR J1903+327 and 4U 1820-30. For plotting this figure the numerical values of physical parameters and constants are as follows: (i) \(a=0.004\), \(b=0.0021\), \(c=0.0107\), \(A=0.4806\), \(B=1.2607\), \(M=1.29 M_{\odot }\), and \(R=8.831\) km for LMC X-4, (ii) \( a=0.00393\), \(b= 0.0025\), \(c=0.01074\), \(A=0.4905\), \(B=1.2293\), \(M=1.3 M_{\odot }\) and \(R=8.849\) km for EXO 1785-248, (iii) \(a=0.005\), \(b=0.0004\), \(c=0.01481\), \(A= 0.4654\), \(B=1.0551\), \(M=1.667 M_{\odot }\) and \(R=9.438\) km for PSR J1903+327, (iv) \(a=0.0055\), \(b= 0.0002\), \(c= 0.0155\), \( A=0.44506\), \(B=1.1286\), \(M=1.58 M_{\odot }\) and \(R=9.1\) km for 4U 1820-30. These numerical values are given in Table 1

The expressions for the matter density, radial and tangential pressures are obtained (by taking \(\psi =a\,r^2+b\),   \(\Phi (r)=B+\tan ^{-1}\sinh \psi \)):

$$\begin{aligned} \rho =\frac{2\,c\,(2+3\,c\,r^2+3\,\cosh 2\psi -4\,a\,r^2\,\sinh 2\psi )}{8\pi \,(1+2\,c\,r^2+\cosh 2\psi )^2}, \end{aligned}$$
(18)
$$\begin{aligned} p_r=\frac{2\,[-c\,B-c\,\tan ^{-1}\sinh \psi +4a\,\cosh \psi ]}{8\pi \,(B+\tan ^{-1}\sinh \psi )\,(1+2\,c\,r^2+\cosh 2\psi )}, \end{aligned}$$
(19)
$$\begin{aligned} p_t=\frac{4\,\cosh \psi [2a\,(1+cr^2+\cosh 2\psi +c\,r^2\,\Phi (r)\,\sinh \psi -a\,r^2\,\sinh 2\psi )-c\,\Phi (r)\,\cosh \psi ]}{8\pi \,(B+\tan ^{-1}\sinh \psi )\,(1+2\,c\,r^2+\cosh 2\psi )^2}. \end{aligned}$$
(20)
Fig. 2
figure 2

Behaviour of energy density \(\rho \) (left panel), and radial pressure, \(p_r\) dotted line, tangential pressure, \(p_t\) solid line (right panel) vs. fractional radius r / R for LMC X-4, EXO 1785-248, PSR J1903+327 and 4U 1820-30. For plotting this figure we have employed data set values of physical parameters and constants as used in Fig. 1

We plot the variation of matter density, radial and tangential pressures in Fig. 2. We can see the density is maximum at the centre and the minimum occurs on the boundary of the star. The radial and tangential pressures are both monotonically decreasing away from the centre. However, \(p_r\) becomes zero at the boundary of the star, which gives the radius of the star. Note that \(p_t\) is nonzero and positive. It is worth pointing out here that the central density is of the order of \(10^{15}\) g/cm\(^3\), which indicates that the nuclear matter is more appropriate for the anisotropic fluid distribution. The expression for the anisotropic factor is given by

$$\begin{aligned} \Delta =\frac{4\,r^2\,(c\,\Phi (r)-2\,a\,\cosh \psi )(c+a\,\sinh 2\psi )}{8\pi \,(B+\tan ^{-1}\sinh \psi )\,(1+2\,c\,r^2+\cosh 2\psi )^2}. \end{aligned}$$
(21)
Fig. 3
figure 3

Behaviour of anisotropy factor \(\Delta \) vs. fractional radius r / R for LMC X-4, EXO 1785-248, PSR J1903+327 and 4U 1820-30. For plotting this figure we have employed data set values of physical parameters and constants as used in Figs. 1 and 2

The pressure anisotropy of the matter plays an important role in determining the stability of the model. Since the force due to anisotropy can be defined as \(F=\frac{2\,\Delta }{r}\), which implies if \(\Delta \) is positive then the direction of the force is outward; however, the force will be directed inward if \(\Delta \) is negative. But the existence of a repulsive force (in the case in which tangential pressure is higher than radial pressure i.e. \(p_t > p_r\)) allows the construction of more compact star models when using an anisotropic fluid than when using an isotropic fluid [27]. From Fig. 3, we can see that \(\Delta \) is positive and finite throughout inside the star. Also it is zero at the centre and attains a maximum at the boundary of the star.

The gradients of pressure and density are given by

$$\begin{aligned} \frac{\mathrm{d}p_r}{\mathrm{d}r}=\frac{2\,r\,\left[ \,p_{1}\,p_{2}\,(a+2\,p_{3}\,\Phi (r)\,\cosh \psi )+a\,p_{r2}\,p_{4}\,\Phi (r)\,\right] }{8\pi \,a\,\cosh \psi \,(B+\tan ^{-1}\sinh \psi )^2\,(1+2\,c\,r^2+\cosh 2\psi )^2},\nonumber \\ \end{aligned}$$
(22)
$$\begin{aligned} \frac{\mathrm{d}p_t}{\mathrm{d}r}=\frac{2\,r\,\left[ \,a\,p_{2}\,p_{5}-a\,p_{2}\,p_{5}\,\Phi (r)+4\,p_{3}\,p_{5}\,\Phi (r)\,\cosh \psi -a\,p_{2}\,(p_{6}+p_{7})\,\Phi (r)\,\right] }{8\pi \,a\,(B+\tan ^{-1}\sinh \psi )^2\,(1+2\,c\,r^2+\cosh 2\psi )^3}, \end{aligned}$$
(23)
$$\begin{aligned} \frac{\mathrm{d}\rho }{\mathrm{d}r}=\frac{4\,c\,r\,\left[ \,2\,\rho _{1}\,(\,c\,\Phi (r)-4\,a\,\cosh \psi \,)-4\,\rho _{2}\,(c+a\,\sinh 2\psi )\right] }{8\pi \,(1+2\,c\,r^2+\cosh 2\psi )^3}.\nonumber \\ \end{aligned}$$
(24)

In the above we have set

$$\begin{aligned} p_{1}= & {} [\,c\,\Phi (r)\!-\!4\,a\,\cosh \psi \,], \,\, p_{2}\!=\![\,1\!+\!2\,c\,r^2\!+\!\cosh 2\psi \,],\,\\ p_{3}= & {} [\,c+a\,\sinh 2\psi \,],\,\,\, p_{4}=[\,-c+2\,a\,\sinh 2\psi \,], \,\, \\ p_5= & {} [\,c\,\Phi (r)\,\cosh \psi -2a\,(1+c\,r^2\\&+\cosh 2\psi +c\,r^2\,\Phi (r)\,\sinh \psi -a\,r^2\,\sinh 2\psi )\,],\\ p_{6}= & {} \left[ \,a\,c\,r^2\,\Phi (r)+(c-2\,a^2\,r^2)\,\cosh \psi \right. \\&\left. +a\,c\,r^2\,\Phi (r)\,\cosh 2\psi \,+2\,a^2\,r^2\,\cosh 3\psi \right] ,\\ p_{7}= & {} \left[ \,-a\,\sinh \psi -a\,\sinh \psi -2\,a\,c\,r^2\right. \\&\left. \sinh \psi -c\,\Phi (r)\,\sinh \psi \,\cosh \psi -a\,\sinh 3\psi \,\right] ,\\ \rho _1= & {} [\,c-4a^2\,r^2\,\cosh 2\psi +a\,\sinh 2\psi \,], \\ \rho _2= & {} [\,3+2\,c\,r^2+3\,\cosh 2\psi -4\,a\,r^2\,\sinh 2\psi \,]. \end{aligned}$$

4 Bounds on the parameters and matching conditions

4.1 Bounds on the parameters

Since the radial pressure \(p_r\) and the tangential pressure \(p_t\) are positive and finite inside the star we obtain the upper bound of B as

$$\begin{aligned} B\,\,< \,\left( \,\frac{4\,a\,\cosh (b)}{c}-\tan ^{-1}\sinh (b)\,\right) . \end{aligned}$$
(25)

Also the fluid model must satisfy the Zeldovich condition i.e. \(p_r/\rho <1\) and \(p_t/\rho <1\) everywhere inside the star, which gives the lower bound of B:

$$\begin{aligned} \left( \,\frac{a\,\cosh (b)}{c}-\tan ^{-1}\sinh (b)\,\right) \,\,<\,\,B. \end{aligned}$$
(26)

From Eq. (25) and Eq. (26), we get the following inequality:

$$\begin{aligned}&\left[ \,\frac{a\,\cosh (b)}{c}-\tan ^{-1}\sinh (b)\,\right] \nonumber \\&\quad< B <\left[ \,\frac{4\,a\,\cosh (b)}{c}-\tan ^{-1}\sinh (b)\,\right] . \end{aligned}$$
(27)

The behaviour of \(p_r/\rho \) and \(p_t/\rho \) is shown in Fig. 4. From this figure it is clear that both \(p_r/\rho \) and \(p_t/\rho \) are less than 1 everywhere inside the anisotropic star, which shows that our fluid model satisfies the Zeldovich condition.

Fig. 4
figure 4

Behaviour of pressure–density ratio \(p_i/\rho \) vs. fractional radius r / R for LMC X-4, EXO 1785-248, PSR J1903+327 and 4U 1820-30. For plotting this figure the numerical values of physical parameters and constants are as follows: (i) \(a=0.004\), \(b=0.0021\), \(c=0.0107\), \(A=0.4806\), \(B=1.2607\), \(M=1.29 M_{\odot }\), and \(R=8.831\) km for LMC X-4, (ii) \( a=0.00393\), \(b= 0.0025\), \(c=0.01074\), \(A=0.4905\), \(B=1.2293\), \(M=1.3 M_{\odot }\) and \(R=8.849\) km for EXO 1785-248, (iii) \(a=0.005\), \(b=0.0004\), \(c=0.01481\), \(A= 0.4654\), \(B=1.0551\), \(M=1.667 M_{\odot }\) and \(R=9.438\) km for PSR J1903+327, (iv) \(a=0.0055\), \(b= 0.0002\), \(c= 0.0155\), \(A=0.44506\), \(B=1.1286\), \(M=1.58 M_{\odot }\) and \(R=9.1\) km for 4U 1820-30

4.2 Matching conditions

To find the arbitrary constants A and B, we must match our interior solution to the exterior Schwarzschild solution at the boundary of the star. The line element of the exterior Schwarzschild solution is given by

$$\begin{aligned} \mathrm{d}s^{2}= & {} \left( 1-\frac{2M}{r} \right) \, \mathrm{d}t^{2} -r^{2} (\mathrm{d}\theta ^{2} +\sin ^{2} \theta \, \mathrm{d}\phi ^{2} )\nonumber \\&-\left( 1-\frac{2M}{r} \right) ^{-1} \mathrm{d}r^{2}, \end{aligned}$$
(28)

where the constant mass M provides the total mass of the anisotropic star within \(r=R\). By matching of \(e^{\nu }\) and \(e^{\lambda }\) at the surface of the star (\(r=R\)) (continuity of first fundamental form) we get

$$\begin{aligned} A^2\,\left[ \,B + \tan ^{-1}\sinh (a\,R^2+b)\,\right] ^2=e^{\nu _R}=1-\frac{2M}{R} , \end{aligned}$$
(29)
$$\begin{aligned} \frac{1+\cosh [2(aR^2+b)]}{1+2cR^2+\cosh [2(aR^2+b)]} =e^{-\lambda _R}=1-\frac{2M}{R}. \end{aligned}$$
(30)

For fixing the arbitrary constants, the second fundamental form (\(\partial g_{44}/\partial r\)) also has to be matched at the boundary \(r=R\). By matching of \(\partial g_{44}/\partial r\) at the surface of the star we get a zero radial pressure at the boundary [28]. Then \(p_r=0\) at \(r=R\) provides the value of the arbitrary constant,

$$\begin{aligned} B=\frac{-c\,\tan ^{-1}\sinh (aR^2+b)+4\,a\,\cosh (aR^2+b)}{c}. \end{aligned}$$
(31)

Then using Eqs. (29) and (30) together with Eq. (31), we obtain the values of constant A and total mass M:

$$\begin{aligned} A\!=\!\frac{\cosh (a\,R^2\!+\!b)}{\sqrt{\cosh ^{2}(aR^2\!+\!b)\!+\!c\,R^2\,}\,[\,B \!+\! \tan ^{-1}\sinh (aR^2+b)\,]},\nonumber \\ \end{aligned}$$
(32)
$$\begin{aligned} M=\frac{c\,R^3}{1+2c\,R^2+\cosh (2aR^2+2b)}. \end{aligned}$$
(33)
Fig. 5
figure 5

Behaviour of radial velocity, \(v_r\), (dotted line) and tangential velocity, \(v_t\), (solid line) vs. fractional radius r / R for LMC X-4, EXO 1785-248, PSR J1903+327 and 4U 1820-30. For plotting this figure we have employed data set values of physical parameters and constants which are the same as used in Fig. 4

5 Salient features of anisotropic models

5.1 Well-behaved property of the solution

For a well-behaved nature of the solution, the velocity of sound must be less than the velocity of light, and it should decrease monotonically throughout the anisotropic star (Fig. 5). For this purpose we have to calculate the radial and tangential speed of sound as

$$\begin{aligned} v_r=\sqrt{\frac{\mathrm{d}p_r}{\mathrm{d}\rho }}=\sqrt{\frac{\mathrm{d}p_r/\mathrm{d}r}{\mathrm{d}\rho /\mathrm{d}r}}, \end{aligned}$$
(34)
$$\begin{aligned} v_t=\sqrt{\frac{\mathrm{d}p_t}{\mathrm{d}\rho }}=\sqrt{\frac{\mathrm{d}p_t/\mathrm{d}r}{\mathrm{d}\rho /\mathrm{d}r}}. \end{aligned}$$
(35)

5.2 Dominant energy conditions

For a physically reasonable anisotropic solution the energy momentum tensor has to obey the following dominant energy conditions:

  1. (i)

    The null energy condition (NEC) implies that local mass-energy density must not be negative: \(\rho \ge 0\),

  2. (ii)

    The weak dominant energy condition (WDEC) implies that the flow of energy inside star must not be faster than the velocity of light: \(\rho -p_r \ge 0,~\rho -p_t\ge 0\),

  3. (iii)

    The strong dominant energy condition (SDEC) implies that the flow of energy inside the star must not be faster than one-third of the light velocity: \(\rho -3p_r\ge 0\), \(\rho -3p_t\ge 0\).

Fig. 6
figure 6

Behaviour of dominant energy conditions vs. fractional radius r / R for LMC X-4 (top left), EXO 1785-248 (top right), PSR J1903+327 (bottom left) and 4U 1820-30 (bottom right). For plotting this figure the numerical values of physical parameters and constants are as follows: (i) \(a=0.004\), \(b=0.0021\), \(c=0.0107\), \(A=0.4806\), \(B=1.2607\), \(M=1.29 M_{\odot }\), and \(R=8.831 km\) for LMC X-4, (ii) \( a=0.00393\), \(b= 0.0025\), \(c=0.01074\), \(A=0.4905\), \(B=1.2293\), \(M=1.3 M_{\odot }\) and \(R=8.849\) km for EXO 1785-248, (iii) \(a=0.005\), \(b=0.0004\), \(c=0.01481\), \(A= 0.4654\), \(B=1.0551\), \(M=1.667 M_{\odot }\) and \(R=9.438\) km for PSR J1903+327, (iv) \(a=0.0055\), \(b= 0.0002\), \(c= 0.0155\), \( A=0.44506\), \(B=1.1286\), \(M=1.58 M_{\odot }\) and \(R=9.1\) km for 4U 1820-30

Table 1 Numerical values of physical parameters a, b, c, R (km), \(M\left( M_\odot \right) \) for different values of n [30]
Table 2 The central density, surface density, central pressure and mass–radius ratio for compact star candidates

From Fig. 6 it is clear that all energy conditions are satisfied within the compact star.

5.3 Mass–radius relation

For any physical valid star model according to Buchdahl [29] the mass to radius ratio for a perfect fluid model should be \(2M/R< 8/9\). Later on Mak and Harko [31] have proposed this relation in a more generalized form which can be written

$$\begin{aligned} M_{\mathrm{eff}}=\frac{\kappa }{2}\int _0^{R}\rho \, r^{2}\mathrm{d}r=\frac{c\,R^3}{1+2c\,R^2+\cosh (2aR^2+2b)}.\nonumber \\ \end{aligned}$$
(36)

In this connection we would like to compare our proposed compact star model with the observed data of different realistic objects. For this purpose we have calculated the physical parameters for the models (see Tables 1, 2) by taking the mass of the compact stars LMC X-4, EXO 1785-248, PSR J1903+327 and 4U 1820-30. The obtained radii of the different compact stars are given in Table 1, which are in good agreement with the proposed values of Gangopadhyay et al. [30].

5.4 Surface redshift

As is well known the compactification parameter of the compact star is given by

$$\begin{aligned} u(R)=\frac{m(R)}{R}=\frac{c\,R^3}{1+2c\,R^2+\cosh (2aR^2+2b)}. \end{aligned}$$
(37)

Then in connection with the above compactification parameter the surface redshift \((z_s)\) can be obtained directly by

$$\begin{aligned} z_s\!=\!\frac{1\!-\![1\!-\!2u]^{\frac{1}{2}}}{[1\!-\!2u]^{\frac{1}{2}}}\!=\!\sqrt{\frac{1\!+\!2cR^2+\cosh [2(aR^2+b)]}{1+\cosh [2(aR^2+b)]}}-1.\nonumber \\ \end{aligned}$$
(38)

From Eq. (38) we can see that the surface redshift cannot be arbitrarily large as it depends upon the compactness parameter \(u=m/R\). The behaviour of the redshift inside the star can be seen in Fig. 7, which can be obtained by the formula \(z=e^{-\nu /2}-1\).

Fig. 7
figure 7

Variation of redshift (Z) with the fractional coordinate r / R. For plotting this figure the numerical values of the physical parameters and constants are as follows: (i) \(a=0.004\), \(b=0.0021\), \(c=0.0107\), \(A=0.4806\), \(B=1.2607\), \(M=1.29 M_{\odot }\), and \(R=8.831\) km for LMC X-4, (ii) \( a=0.00393\), \(b= 0.0025\), \(c=0.01074\), \(A=0.4905\), \(B=1.2293\), \(M=1.3 M_{\odot }\) and \(R=8.849\) km for EXO 1785-248, (iii) \(a=0.005\), \(b=0.0004\), \(c=0.01481\), \(A= 0.4654\), \(B=1.0551\), \(M=1.667 M_{\odot }\) and \(R=9.438\) km for PSR J1903+327, (iv) \(a=0.0055\), \(b= 0.0002\), \(c= 0.0155\), \( A=0.44506\), \(B=1.1286\), \(M=1.58 M_{\odot }\) and \(R=9.1\) km for 4U 1820-30

5.5 Stability of the solution

5.5.1 Stability of anisotropic models via cracking

In our anisotropic fluid model, to verify stability we plot the radial (\(v_{r}=\sqrt{\mathrm{d}p_r/\mathrm{d}\rho }\)) and transverse (\(v_{t}=\sqrt{\mathrm{d}p_t/\mathrm{d}\rho }\)) sound speeds in Fig. 5. It can be observed that both velocities satisfy the inequalities \(0< v^2_{r} < 1\) and \(0< v^2_{t} < 1\) everywhere within the stellar object (Fig. 8), which obeys the anisotropic fluid models [32, 33].

Fig. 8
figure 8

Behaviour of square of radial velocity, \(v^2_r\), (dotted line) and tangential velocity, \(v^2_t\), (solid line) vs. fractional radius r / R for LMC X-4, EXO 1785-248, PSR J1903+327 and 4U 1820-30. For plotting this figure the numerical values of physical parameters and constants are as follows: (i) \(a=0.004\), \(b=0.0021\), \(c=0.0107\), \(A=0.4806\), \(B=1.2607\), \(M=1.29 M_{\odot }\), and \(R=8.831 km\) for LMC X-4, (ii) \( a=0.00393\), \(b= 0.0025\), \(c=0.01074\), \(A=0.4905\), \(B=1.2293\), \(M=1.3 M_{\odot }\) and \(R=8.849\) km for EXO 1785-248, (iii) \(a=0.005\), \(b=0.0004\), \(c=0.01481\), \(A= 0.4654\), \(B=1.0551\), \(M=1.667 M_{\odot }\) and \(R=9.438\) km for PSR J1903+327, (iv) \(a=0.0055\), \(b= 0.0002\), \(c= 0.0155\), \(A=0.44506\), \(B=1.1286\), \(M=1.58 M_{\odot }\) and \(R=9.1\) km for 4U 1820-30

To check whether the local anisotropic matter distribution is stable or not, we use the proposal of Herrera [32], known as the criterion of cracking (or overturning) of the star. This indicates that the region is potentially stable where the radial velocity of sound is greater than the transverse velocity of sound. We can easily say that \(0< v^2_{r}-v^2_{t} < 1 \) (dotted line) and \(-1< v^2_{t} - v^2_{r} < 0\) (solid line) as can be seen in Fig. 9. Hence, we conclude that our compact star model provides a stable configuration.

Fig. 9
figure 9

Behaviour of \(v^2_r-v^2_t\) (dotted line) and \(v^2_t-v^2_r\) (solid line) vs. fractional radius r / R for LMC X-4, EXO 1785-248, PSR J1903+327 and 4U 1820-30. For plotting of this figure we have employed data set values of the physical parameters and constants which are the same as used in Fig. 8

5.5.2 Stability via adiabatic index

The stability of the relativistic anisotropic star also depends upon the adiabatic index \(\Gamma \). Heintzmann and Hillebrandt [34] proposed that neutron star models with anisotropic equation of state are stable if \(\gamma > 4/3\). However, according to Newton’s theory of gravitation the isotropic neutron star model has no upper mass limit for the adiabatic index \(\gamma > 4/3\) [35]. The adiabatic index \(\Gamma \) is defined by

$$\begin{aligned} \Gamma =\frac{p_r+\rho }{p_r}\,\frac{\mathrm{d}p_r}{\mathrm{d}\rho }. \end{aligned}$$
(39)

For a relativistic anisotropic fluid sphere the stability condition is given by

$$\begin{aligned} \Gamma >\frac{4}{3} \left[ 1 +3\pi \frac{\rho _0p_{r0}}{|p_{r0}^\prime |}r+\frac{(p_{t0}-p_{r0})}{|p_{r0}^\prime |r}\right] , \end{aligned}$$
(40)

where \(p_{r0}\), \(p_{t0}\), and \(\rho _0\) denote the initial radial pressure, tangential pressure and energy density, respectively, in the static equilibrium condition which satisfies the TOV equation (15). However, the second and last terms inside the square brackets correspond to the anisotropic and relativistic corrections (being positive quantities), which increase the instability range of the adiabatic index. For this purpose we have plotted \(\Gamma \) vs. r / R. The behaviour of the adiabatic index is shown in Fig. 10, which shows that \(\Gamma >\frac{4}{3}\) everywhere inside the compact star model.

Fig. 10
figure 10

Behaviour of adiabatic index \(\Gamma _r\) vs. fractional radius r / R for LMC X-4, EXO 1785-248, PSR J1903+327 and 4U 1820-30. For plotting this figure we have employed data set values of physical parameters and constants which are the same as used in Figs. 8 and 9

5.5.3 Stable equilibrium condition via TOV equation

The Tolman–Oppenheimer–Volkoff (TOV) equation describes the interior structure of the compact star which is a relationship between two physical quantities, the radial pressure and the density. Using the TOV equation we want to examine whether our present model is in a stable equilibrium stage under the three forces, viz. anisotropic force (\(F_a=2(p_t-p_r)/r\)), hydrostatics force (\(F_h=-\mathrm{d}p_r/\mathrm{d}r\)) and gravitational force (\(F_g=-\nu '\,(\rho +p_r)/r\)). This implies that the sum of three different forces becomes zero:

$$\begin{aligned} F_a+F_h+F_g=0. \end{aligned}$$
(41)

The explicit form of the above three different forces for this solution is given by

$$\begin{aligned} F_a=\frac{8\,r\,(c\,\Phi (r)-2\,a\,\cosh \psi )(c+a\,\sinh 2\psi )}{8\,\pi \,(B+\tan ^{-1}\sinh \psi )\,(1+2\,c\,r^2+\cosh 2\psi )^2},\nonumber \\ \end{aligned}$$
(42)
$$\begin{aligned} F_h=-\frac{\mathrm{d}p_r}{\mathrm{d}r}, \end{aligned}$$
(43)
$$\begin{aligned} F_g\!=\!-\!\frac{16\,a\,r\,\left[ \,c\,\Phi (r)\,\cosh \psi \!+\!a\,p_2\!-\!2\,a\,c\,r^2\,\Phi (r)\,\sinh \psi \,\right] }{8\,\pi \,(B\!+\!\tan ^{-1}\sinh \psi )^2\,(1\!+\!2\,c\,r^2+\cosh 2\psi )^2}.\nonumber \\ \end{aligned}$$
(44)

The behavior of above forces can see in Fig. 11.

Fig. 11
figure 11

Behaviour of different forces vs. fractional radius r / R for LMC X-4 (top left), EXO 1785-248 (top right), PSR J1903+327 (bottom left) and 4U 1820-30 (bottom right). For plotting this figure the numerical values of physical parameters and constants are as follows: (i) \(a=0.004\), \(b=0.0021\), \(c=0.0107\), \(A=0.4806\), \(B=1.2607\), \(M=1.29 M_{\odot }\), and \(R=8.831 km\) for LMC X-4, (ii) \( a=0.00393\), \(b= 0.0025\), \(c=0.01074\), \(A=0.4905\), \(B=1.2293\), \(M=1.3 M_{\odot }\) and \(R=8.849\) km for EXO 1785-248, (iii) \(a=0.005\), \(b=0.0004\), \(c=0.01481\), \(A= 0.4654\), \(B=1.0551\), \(M=1.667 M_{\odot }\) and \(R=9.438\) km for PSR J1903+327, (iv) \(a=0.0055\), \(b= 0.0002\), \(c= 0.0155\), \( A=0.44506\), \(B=1.1286\), \(M=1.58 M_{\odot }\) and \(R=9.1\) km for 4U 1820-30

5.5.4 Harrison–Zeldovich–Novikov stability criterion:

Recently, Singh et al. [40] have employed the Harrison–Zeldovich–Novikov [41, 42] criterion for investigating the stability of the anisotropic compact star models (Fig. 12). This criterion is that the configuration is stable only if the mass of the compact star is increasing with central density i.e. \(\mathrm{d}M/\mathrm{d}\rho _0 > 0\); however, it is unstable if \(\mathrm{d}M/\mathrm{d}\rho _0 < 0\).

Let us define the mass function of our static anisotropic fluid solution in terms of the central density by

$$\begin{aligned} M=\frac{4\,\pi \,\rho _0\,R^3\,(1+\cosh 2b)^2}{2+3\,\cosh 2b+8\,\pi \,\rho _0\,(1+\cosh 2b)^2+\cosh (2aR^2+2b)}.\nonumber \\ \end{aligned}$$
(45)

The derivative of Eq. (45) with respect to \(\rho _0\) gives

$$\begin{aligned} \frac{\mathrm{d}M}{\mathrm{d}\rho _0}=\,\frac{16 \pi R^3 (\cosh b)^4 ~ [2+3\,\cosh 2b + \cosh 2(a R^2 + b)]}{[2 + 12 \,\rho \, \pi + (3 + 16 \rho \, \pi ) \cosh 2 b + 4 \rho \, \pi \cosh 4 b + \cosh 2(b+aR^2)]^2}. \end{aligned}$$
(46)

From Fig. 12, it is clear that our anisotropic models are stable according to the Harrison–Zeldovich–Novikov stability criterion. It is noted that the stability of our configurations is increased with increasing radii and there is no change after attaining a maximum value for the respective central densities. It important to note that the curve starts leaving off, i.e. \(\mathrm{d}M/\mathrm{d}\rho _0 = 0\), after reaching its maximum value, which indicates that the configuration is rendered unstable.

Fig. 12
figure 12

Behaviour of mass (\(M_\odot \)) vs. central density \(\rho _0 (0 - 2.6993\times 10^{15}\) g/cm\(^{3}\)) for the different compact stars

5.6 Herrera’s generating functions for the present embedding class one solution:

The algorithm for all possible anisotropic fluid solution via generating functions for the Einstein field equations is given by Herrera et al. [43],

$$\begin{aligned} e^{\lambda (r)}=\frac{z^2\,e^{\int {\left[ \frac{4}{r^2z(r)}+2\,z(r)\right] \mathrm{d}r}}}{r^6\left[ -2\,\int {\frac{z(r)(1+\Pi (r)\,r^2)e^{\int {\left[ \frac{4}{r^2z(r)}+2\,z(r)\right] \mathrm{d}r}}}{r^8}\mathrm{d}r}+E\right] }\nonumber \\ \end{aligned}$$
(47)

where E is arbitrary constants of integration; then the corresponding generating functions are

$$\begin{aligned} z(r)=\left[ \frac{\nu ^{\prime }}{2}+\frac{1}{r}\right] , \, \, \Pi =8\pi \,(p_r-p_t). \end{aligned}$$

Using the above algorithm the generating functions for the present embedding class one solution (using Eq. (10)):

$$\begin{aligned} z(r)=\frac{D\,\sqrt{e^{\lambda (r)}-1}}{C+D\,\int {\sqrt{e^{\lambda (r)}-1}\,\mathrm{d}r}}+\frac{1}{r}, \end{aligned}$$
(48)
$$\begin{aligned}&\Pi =\frac{D\,\sqrt{e^{\lambda (r)}-1}}{2\,e^{\lambda }}\,\left[ \frac{\,\sqrt{e^{\lambda (r)}-1}}{B\,r}-\frac{1}{C+D\int {\sqrt{e^{\lambda (r)}-1} \mathrm{d}r}}\right] \nonumber \\&\times \left( \frac{\lambda ^{\prime }}{e^{\lambda }-1}-\frac{2}{r}\right) . \end{aligned}$$
(49)

By plugging Eq. (16) into Eqs. (48) and (49) we get the following generating functions z(r) and \(\Pi \):

$$\begin{aligned} z(r)=\frac{2\,a\,r}{[\,B+\tan ^{-1}\sinh (ar^2+b)\,]\,\cosh (ar^2+b)}+\frac{1}{r},\nonumber \\ \end{aligned}$$
(50)
$$\begin{aligned} \Pi =\frac{4\,r^2\,[c\,(B+\tan ^{-1}\sinh \psi )-2\,a\,\cosh \psi ]\,(c+a\,\sinh 2\psi )}{8\pi \,(B+\tan ^{-1}\sinh \psi )\,(1+2\,c\,r^2+\cosh 2\psi )^2}.\nonumber \\ \end{aligned}$$
(51)

It is clear that the present system can be completely determined by one generating function through \(e^{\lambda (r)}\) and an additional ansatz in the form of a class one condition.

6 Physical analysis and discussion

In the present paper we have investigated the nature of anisotropic fluid spheres, by utilizing the Karmarkar condition, which are also known as spacetimes of embedding class one. To outline this investigation we have considered the following assumption for the gravitational potential: \(\lambda = \ln [1+2\,cr^2+\cosh (2\,ar^2+2\,b)]-\ln [1+\cosh (2\,ar^2+2\,b)]\), where a and c are nonzero positive parameters. The choices of a and c are as follows: (i). If \(c=0\) then we have a flat spacetime. (ii). If \(a=0\) then there is no pressure-free boundary unless \(c=0\). Under the above restrictions, we have obtained new anisotropic fluid spheres for \(a\ne 0\) and \(c\ne 0\).

The main physical features of the present solution can be used to explore the nature of anisotropic fluid spheres as follows:

  1. (i)

    Firstly we have developed a relation between the gravitational potentials \(e^{\nu }\) and \(e^{\lambda }\) for the spherically symmetric line element by using the Karmarkar condition. Due to this relation, we can convert all the differential equations in terms of one of the metric coefficients (the full details can be seen in the references by Maurya et al. [36, 37]). For this purpose we have assumed a totally new metric potential \(e^{\lambda }=[{1+2c\,r^2+\cosh 2(ar^2\!+\!b)}]/[{1+\cosh 2(ar^2\!+\!b)}]\) to find the anisotropic solution for realistic fluid spheres. The variation of \(e^{\nu }\) and \(e^{\lambda }\) can be seen in Fig. 1.

  2. (ii)

    The fluid spheres are purely anisotropic because embedding class one solutions can give only two types of perfect fluid solutions which are namely the Kohlar–Chao or Schwarzschild solutions; otherwise the metric turns out to be flat. As we can see the radial pressure \(p_r\) is zero at the boundary but the tangential pressure \(p_t\) does not vanish at \(r=R\); however, both are equal at the centre of the fluid sphere (Fig. 2). Also the pressure anisotropy vanishes everywhere inside the fluid sphere if and only if \(c=0\). In this situation the pressures and density become zero and the metric turns out to be flat. As we can see in Fig. 3 the anisotropy is increasing throughout, while it is zero at the centre, which implies that \(p_r\) and \(p_t\) are not equal except at the centre of the fluid sphere.

  3. (iv)

    Since \(p_r/\rho \) and \(p_t/\rho \) lie between 0 and 1 everywhere within the sphere, our fluid sphere satisfies the Zeldovich condition. Moreover, \(p_r/\rho \) and \(p_t/\rho \) are monotonically decreasing throughout the inside the sphere (Fig. 4).

  4. (v)

    For the well behaved nature of the solution the velocity of sound should be decreasing throughout the fluid sphere and must be less than the velocity of light. From Fig. 5, it is clear that both \(v_r\) and \(v_t\) are decreasing and less than 1, which shows that our anisotropic solution is well behaved. Also all dominant energy conditions are satisfied, a necessary physical requirement everywhere inside the fluid sphere (Fig. 6).

  5. (vi)

    The surface redshift is also determined by using the compactness factor for the fluid sphere. For the fluid sphere PSR J1903+327, the surface redshift turns out to be \(z_s=0.44505\), which is a maximum. The redshift without cosmological constant for isotropic fluid spheres is bound by \(z_s\le 2\) [29, 38, 39]. However, in the presence of the cosmological constant Bohmer and Harko [39] argued that the surface redshift must satisfy the restriction \(z_s\le 5\) for anisotropic fluid spheres. Therefore the value of the surface redshift for our anisotropic spheres seems to be compatible with realistic compact objects. Moreover, the surface redshift cannot be arbitrarily large because it depends on the compactness factor \(u=M/R\).

  6. (vii)

    We have also discussed the stability of the fluid sphere (which is the most vital physical requirement) by using the following facts: (a) the cracking concept proposed by Herrera [32], (b) the variation of the adiabatic index inside the fluid spheres, (c) the stable equilibrium condition by using the TOV equation and (d) the Harrison–Zeldovich–Novikov stability criterion. The results are as follows. It can be observed in Fig. 8 that the velocity \(v^2_r\) and \(v^2_t\) lie in the ranges: (i) \(0.053\le v^2_r\le 0.107\), \(0.017\le v^2_t\le 0.025\) for LMC X-4, (ii) \(0.056\le v^2_r\le 0.11\), \(0.019\le v^2_t\le 0.027\) for EXO 1785-248, (iii) \(0.04274\le v^2_r\le 0.1375\), \(0.0419\le v^2_t\le 0.0654\) for PSR J1903+327 and (iv) \(0.0338\le v^2_r\le 0.1305\), \(0.0328\le v^2_t\le 0.0562\) for 4U 1820-30. Also the radial velocity (\(v_r\)) is always greater than the tangential velocity (\(v_t\)) everywhere inside the fluid sphere (Fig. 5). We plot the figure for \(v^2_r-v^2_t\) and \(v^2_t-v^2_r\) to apply the Herrera cracking concept, observing that there is no change in sign of \(v^2_r-v^2_t\) and \(v^2_t-v^2_r\) (Fig. 9). This implies that our anisotropic fluid models are stable. The variation of the adiabatic index is given in Fig. 10, which shows that the value of \(\Gamma \) is more than 4 / 3 within the fluid models. We discuss the equilibrium condition for the anisotropic fluid model by using the Tolman–Oppenheimer–Volkoff (TOV) equation. For this purpose we plot figures for the TOV equation in terms of different forces. From Fig. 11, we can observe the gravitational force \(F_g\) is counter-balanced by the joint action of hydrostatic force \(F_g\) and anisotropic force \(F_a\) for all stars LMC X-4, EXO 1785-248, PSR J1903+327 and 4U 1820-30. Finally, in this subsection we also checked the stability of the models via the Harrison–Zeldovich–Novikov stability criterion, which states that any configuration is stable so long as \(\mathrm{d}M / \mathrm{d}\rho _0 > 0\), or the mass increases with central density \(\rho _0\), and unstable when as \(\mathrm{d}M / \mathrm{d}\rho _0 < 0\), or the mass decreases with the increase of central density \(\rho _0\). From Fig. 12 it is clear that the mass is increasing with central density \(\rho _0\), which shows that the present anisotropic configuration is stable.

  7. (viii)

    Finally, we proposed the generating functions for all the spherically symmetric anisotropic solutions of Einstein’s field equations which were discovered by Herrera et al. [43], being generated from two very primitive functions.

The overall final comment is that the Karmarkar embedding condition describes a rich class of anisotropic compact spheres which are physically viable in relativistic astrophysics.