Scientific Calculations with Julia/Big Bang
Using Gauss's Law, we can arrive at a very simple and transparent demonstration of a temporal singularity analogous to that of the Big Bang, which gave rise to the universe 13.8 billion years ago.
Assuming that the universe can be represented by a sphere of radius r (the radius of curvature of the universe), then by Gauss's Law, the force on a particle located at a distance r depends only on the mass M(r) contained in the sphere, resulting in the differential equation:
If we assume a homogeneous universe, so that the average density is the same everywhere, knowing the formula for the volume of a sphere, we have:
Assuming constant density, substituting this equation into the previous one yields the differential equation:
Solving the equation with wxMaxima
Using the wxMaxima program to find the general and particular solution to the equation yields:
assume(G>0,ρ>0);
'diff(r,t,2)=-(4*π*G*ρ)/3 * r;
The general solution is:
ode2(%, r, t);
Since the second derivative of r is always negative, then r(t) is concave and therefore there is a time in which the radius r is 0 (cosmological singularity of the big bang). Setting the result to 0 for t=0 yields the following particular solution:
ic2(%, t=0, r=0, 'diff(r,t)=1);
Graphing the particular solution with Julia
We write the differential equation as a system:
- (u[1] = r(t))
- (u[2] = \dot r(t))
using DifferentialEquations
using Plots
function odefunc!(du,u,p,t)
G, ρ = p
du[1] = u[2]
du[2] = -(4π*G/3)*ρ*u[1]
end
Let's solve the differential equation:
G = 6.67e-11
ρ = 1e-26 # example density in kg/m^3
u0 = [0.0, 1.0] # r(0)=0, ṙ(0)=1
tspan = (0.0, 1.87e18 )
prob = ODEProblem(odefunc!, u0, tspan, (G, ρ))
Let's plot the graph:
sol = solve(prob)
plot(sol, vars=(0,1), xlabel="t", ylabel="r(t)", title="Particular solution of r''\n(beginning and end of the universe)")

Conclusions
The constant density model uses an unrealistic assumption; in fact, for the universe, density decreases with expansion (as the radius of curvature increases). This analysis is just a very useful exercise, but it doesn't correspond to real physics, nor to Friedmann's models, where, however, for the density diverges to +infinity, which would be precisely the initial cosmological singularity of the Big Bang.