Search code examples
matlaboctavepde4d

How to interpolate and plot a 4-Dimensional hamburger?


I have solved the heat equation in octave via finite difference and produced the following 3-D plot whose point colors correspond to the temperatures in each element of my three dimensional hamburger.

My computational resources limit the resolution at which I may solve my burger. Thus the only way to get the plot I want is to make my scatter3 points huge blobs of color and it looks kind of bad.

[x,y,z] = meshgrid(1:nx,1:ny,1:nz)                       % Defines a grid to plot on
scatter3(x(:), y(:), z(:), 40, burgermatrix(:), 's', 'filled')% Point color=value

The Perfect Burger

What I want is a nice gorgeous smooth rectangular prism like this:

Prism

So I figure I need to somehow interpolate between the 3D points that I have. Can anyone help me figure out how to do this?


Solution

  • I might be missing something obvious, but here's the example from octave's help slice:

    [x, y, z] = meshgrid (linspace (-8, 8, 32));
    v = sin (sqrt (x.^2 + y.^2 + z.^2)) ./ (sqrt (x.^2 + y.^2 + z.^2));
    slice (x, y, z, v, [], 0, []);
    [xi, yi] = meshgrid (linspace (-7, 7));
    zi = xi + yi;
    slice (x, y, z, v, xi, yi, zi);
    shading interp; %addition by me
    

    Isn't this exactly what you need? You have your grid (x,y,z), your solutions (T), so you just need to plot it slicing along [0 0 1] etc. Something like

    [xi yi]=meshgrid(unique(x),unique(y));
    slice (x, y, z, T, xi, yi, max(z(:))*ones(size(xi)));
    

    and the same for cuts along the two other axes. (Obviously the unique calls should be substituted with the vectors you already have from which you constructed the 3d mesh in the first place.)

    NOTE: By the way, you should really consider changing the default (jet) colormap. I was yesterday enlightened by a colleague about the viridis colormap made by the SciPy people, see for instance this post and video link therein. Their reasoning is overwhelming, and their colormap is beautiful. This should define it: viridis, although I haven't tried it myself yet.

    (If it wasn't for jet, I'd tell you that your temperature profile seems strongly 1d. Do you happen to have periodic boundary conditions along the vertical walls and homogeneous (i.e. constant) boundary conditions along the horizontal ones?)