Advanced Octave A41 — Fields and three-dimensional representations
Advanced GNU Octave with GX-TXT · Module 07
A surface allows to represent a value that depends on two coordinates. We build a synthetic Gaussian in Octave and visualize it with the three-dimensional renderingr of GX-TXT.
Objectives and prerequisites
They are familiar with matrices and meshgrid, with the publication of Dataset of A13 and with Plot v4. The example uses GX-TXT dev112-P011-bis and GNU Octave 9.4.0. Import superficie.m, register it and run it in the Runner. The Dataset octave_advanced_surface is created-only: for a new execution use a new Session or change its ID in the script.
From reticle to rows
meshgrid builds two matrices of 21 × 21 coordinates between −2 and 2. The function is z = exp(-(x.^2+y.^2)): it reaches 1 at the center and decreases towards the edges. The sizes are dimensionless, indicated with 1 units.
The x(:), y(:) and z(:) expressions run the three matrixes in the same columnar order. Each line of the Dataset therefore contains coordinates and value of the same sample: publishing carriers in different orders would shift values to the surface. The samples are 441.
The three-dimensional PlotSpec declares graph_type = 'cartesian_3d', the Dataset and the IDs of the X, Y and Z variables; the plot_type = 'surface' configuration requires a surface. The validation returns 1 and render produces a variant in the native renderingr.
Read the surface
Open the chart in the Plots tab and double-click the figure; use Fit to fit the window:
The maximum is in correspondence of X = 0 and Y = 0. The perspective and color help to understand the shape, but to read the quantitative values serve coordinates, units and data. The limits displayed include automatic margins: the original lattice remains between −2 and 2 on both axes.
Exercise
- How many samples does the lattice contain?
- How much is the function at the origin?
- Why does
(:)apply in the same way to the three matrices?
Worked solution
- 21 × 21 = 441.
exp(0) = 1.- To keep each coordinate pair in the same row and the value calculated in that position.
Other steps of this project
- Advanced Octave A75 — Dynamical systems in phase space
- Advanced Octave A81 — Geography of the waves and a 3D surface
- Advanced Octave A82 — Age, sex and demographic inequalities
- Advanced Octave A83 — All-cause mortality, certified COVID deaths and surveillance
- Advanced Octave A84 — A reproducible public account
- Advanced Octave A73 — Optimization landscapes and 3D trajectories