The tensor object is a 4x4 cell array. Each cell contains an array of values for each point in spacetime.
T = 1:gridSize(1);
X = 1:gridSize(2);
Y = 1:gridSize(3);
Z = 1:gridSize(4);
% Set Minkowski terms
% This sets all 4x4 terms of the tensor to flat space
% This allows you to delete flat parts of the metric in the assignments
% below
Metric.tensor = setMinkowski(gridSize);
% Assign metric terms
for h = T
for i = X
for j = Y
for k = Z
% Define grid coordinates
t = h*gridScaling(1)-wolrdCenter(1)
x = i*gridScaling(2)-worldCenter(2);
y = j*gridScaling(3)-worldCenter(3);
z = k*gridScaling(4)-worldCenter(4);
% Diagonal terms
Metric.tensor{1,1}(h,i,j,k) = % Your equations as a function of t,x,y,z here
Metric.tensor{2,2}(h,i,j,k) = % Your equations as a function of t,x,y,z here
Metric.tensor{3,3}(h,i,j,k) = % Your equations as a function of t,x,y,z here
Metric.tensor{4,4}(h,i,j,k) = % Your equations as a function of t,x,y,z here
% Time cross terms
Metric.tensor{1,2}(h,i,j,k) = % Your equations as a function of t,x,y,z here
Metric.tensor{1,3}(h,i,j,k) = % Your equations as a function of t,x,y,z here
Metric.tensor{1,4}(h,i,j,k) = % Your equations as a function of t,x,y,z here
% Spatial cross terms
Metric.tensor{2,3}(h,i,j,k) = % Your equations as a function of t,x,y,z here
Metric.tensor{2,4}(h,i,j,k) = % Your equations as a function of t,x,y,z here
Metric.tensor{3,4}(h,i,j,k) = % Your equations as a function of t,x,y,z here
% Assign Symmetric Values
Metric.tensor{2,1}(h,i,j,k) = Metric.tensor{1,2}(h,i,j,k);
Metric.tensor{3,1}(h,i,j,k) = Metric.tensor{1,3}(h,i,j,k);
Metric.tensor{4,1}(h,i,j,k) = Metric.tensor{1,4}(h,i,j,k);
Metric.tensor{3,2}(h,i,j,k) = Metric.tensor{2,3}(h,i,j,k);
Metric.tensor{4,2}(h,i,j,k) = Metric.tensor{2,4}(h,i,j,k);
Metric.tensor{4,3}(h,i,j,k) = Metric.tensor{3,4}(h,i,j,k);
end
end
end
end
End the function
end
Calling Your Function
In the Command Window or in custom script, your metric can be called via:
Similar to building your metric directly via the metric tensor components, you can also build your metric via the 3+1 components.
The defining metric tensor components section gets changed to:
T = 1:gridSize(1);
X = 1:gridSize(2);
Y = 1:gridSize(3);
Z = 1:gridSize(4);
% Set Minkowski terms
% This sets all 4x4 3+1 components to that flat space
% This allows you to delete flat parts of the 3+1 in the assignments
% below
[alpha, beta, gamma] = setMinkowskiThreePlusOne(gridSize);
% Assign 3+1 terms
for h = T
for i = X
for j = Y
for k = Z
% Define grid coordinates
t = h*gridScaling(1)-worldCenter(1)
x = i*gridScaling(2)-worldCenter(2);
y = j*gridScaling(3)-worldCenter(3);
z = k*gridScaling(4)-worldCenter(4);
% Alpha term
alpha(h,i,j,k) = % Your equations as a function of t,x,y,z here
% Beta terms
beta{1}(h,i,j,k) = % Your equations as a function of t,x,y,z here
beta{2}(h,i,j,k) = % Your equations as a function of t,x,y,z here
beta{3}(h,i,j,k) = % Your equations as a function of t,x,y,z here
% Gamma terms
gamma{1,1}(h,i,j,k) = % Your equations as a function of t,x,y,z here
gamma{2,2}(h,i,j,k) = % Your equations as a function of t,x,y,z here
gamma{3,3}(h,i,j,k) = % Your equations as a function of t,x,y,z here
gamma{1,2}(h,i,j,k) = % Your equations as a function of t,x,y,z here
gamma{1,3}(h,i,j,k) = % Your equations as a function of t,x,y,z here
gamma{2,3}(h,i,j,k) = % Your equations as a function of t,x,y,z here
% Assign Symmetric Gamma Terms
gamma{2,1}(h,i,j,k) = gamma{1,2}(h,i,j,k);
gamma{3,1}(h,i,j,k) = gamma{1,3}(h,i,j,k);
gamma{3,2}(h,i,j,k) = gamma{2,3}(h,i,j,k);
end
end
end
end
% Convert 3+1 terms into the Metric
Metric.tensor = threePlusOneBuilder(alpha,beta,gamma);