This is dedicated code to evolve a flat universe with negative present energy density. This universe contains only matter and cosmological constant. Code is written in C++ which generates a text (.txt) file with the outputs: scale factor and cosmic (proper) time. Then a MATLAB script is used to convert text (.txt) file to an excel (.xls) file and to plot.

I have written another code to do all the work (data generating and plotting) in python. I will share that soon.

// Scale Factor and Time (with Negative Omega0) in a Flat Universe

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>

using namespace std;
	double hubbleConst = 7.2e-11;	// in inverse years
	double scaleFactor;
	double scale;
	double scaleLambda;
	double allTime;
	double alpha;
	double beta;
	double gamma;
	double delta;
	double nu;
	double OmegaMatter;
	double OmegaLambda;

int main() 
{
	ofstream file;
	file.open ("matter_lambda_flat_neg_omegaM.txt");
	OmegaMatter = 0.9;
	OmegaLambda = 0.1;
	scaleLambda = ( OmegaMatter / pow(1 - OmegaMatter, 0.33334));
	alpha = 0.66667 * (1 / hubbleConst);
	beta = 1 / sqrt(1 - OmegaMatter);
	
for ( scale = 0; scale < 40 ; scale+=0.001 )
		{	
			gamma = pow( scale / scaleLambda, 1.5);
			delta = pow( scale / scaleLambda, 3);
			nu = log( gamma + sqrt( 1 + delta) );
			scaleFactor = scaleLambda;
			allTime = alpha * beta * nu;
			cout << scale << "	" << allTime << "	" << scaleFactor << endl;
			file << scale << "	" << allTime << "	" << scaleFactor << endl;
		}
	file.close();
	return 0; 
}

And the MATLAB code to produce the plot from the result generated is given below.


data = xlsread('F:\YOUR PATH\matter_lambda_flat_neg_omegaM.xlsx','Sheet1');

scale = data(:,1);
allTime = data(:,2);
scaleFactor = data(:,3);

plot(allTime,scale)
xlabel('Time (in seconds)')
ylabel('Scale')
title(['Scale Factor and Time in a Flat Universe'])

clearvars data raw;

And the desired output comes out like the following.

Share: