Solution (source code)

= Solution

A nonspherical configuration requires the vector form of <hydrostatic equilibrium> and the <Poisson equation>, rather than the spherical mass-coordinate equations:
$$
\nabla P=-\rho\nabla\Phi,\qquad\nabla^2\Phi=4\pi G\rho.
$$
For the same <index-one polytrope>, hydrostatic balance inside the positive-density region gives $\Phi=C-2K\rho$. Thus its interior <mass density> must obey the <Helmholtz equation>
$$
\nabla^2\rho+k^2\rho=0,\qquad k^2=\frac{2\pi G}{K}.
$$
A positive separated solution with the required boundary values is
$$
\boxed{\rho(x,y,z)=\rho_c\sin\frac{\pi x}{L}\sin\frac{\pi y}{L}\sin\frac{\pi z}{L}.}
$$
Its maximum is $\rho_c$ at the centre of the cube and it vanishes on every face. Its Laplacian is $-3\pi^2\rho/L^2$, so it satisfies the interior equations when
$$
\boxed{L=\left(\frac{3\pi K}{2G}\right)^{1/2}=\sqrt3\,R.}
$$
Together with $P=K\rho^2$ and $\Phi=C-2K\rho$, this explicitly constructs the <cubic polytropic interior>.

The mass integral separates into three elementary sine integrals:
$$
M=\rho_c\left(\int_0^L\sin\frac{\pi x}{L}\,dx\right)^3
=\rho_c\left(\frac{2L}{\pi}\right)^3.
$$
Therefore
$$
\boxed{\frac{\overline\rho}{\rho_c}=\frac{M}{L^3\rho_c}=\frac8{\pi^3}.}
$$
This construction satisfies the equations inside the prescribed cube. It does not by itself establish the existence of an isolated self-gravitating star: the interior potential must also match the exterior vacuum field generated by that very <mass density>. That additional physical requirement is addressed in part (c).