Translating 2D Matrix Location to a Specific Node in Higher Dimensional Space (MATLAB)

55 views Asked by At

So I have some code (copied below) that I’ve used to translate location in a matrix representing a 2D space into a specified node within the matrix. I’ve used this to help solve and visualize differential equations problems. I was wondering if someone could tell me how to expand this concept to higher dimension problems? Is it possible to use this concept beyond 3D or is that where the value of this would end?

%Length of space
Lx = 0.5; 
Ly = 0.5;
%Number of nodes in each direction
Nx = 80; 
Ny = 80; 
x = linspace(0,Lx,Nx);
y = linspace(0,Ly,Ny);
dx = x(2)-x(1); 
dy = y(2)-y(1);
N = Nx*Ny;
A = spalloc(N,N,5*N);
b = zeros(N,1);
for i = 1:Nx
    for j = 1:Ny 
        **n = Nx*(j-1)+i;** %This part is the actual translator

Haven’t tried much yet because I’m not sure where to start? How would I change this to account for a z-axis? Is it even possible to expand this to 4D or higher? I’d imagine the 3D version could be handled with another for loop along the lines of “for k =1:Nz” and then edit the existing translator to something like


n = Nz*(k-1)+Nx*(j-1)+i


If that is wrong, let me know. But more so, is it viable to expand this to 4+ dimensions? And is there a specific term for this or no? I’ve just been calling it a translator.

0

There are 0 answers