Advanced Octave A41 — Fields and three-dimensional representations

by Giux GX-TXT, octave-en, scripts-en 2 min read

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

  1. How many samples does the lattice contain?
  2. How much is the function at the origin?
  3. Why does (:) apply in the same way to the three matrices?

Worked solution

  1. 21 × 21 = 441.
  2. exp(0) = 1.
  3. To keep each coordinate pair in the same row and the value calculated in that position.

Download the Module 07 scripts (ZIP)

#GNU Octave #GX-TXT #GX-TXT public APIs

Other steps of this project

Leave a Reply

Your email address will not be published. Required fields are marked *