A mass and a spring to read the Legendre transform in a concrete state.

A mass attached to a spring is one metre from equilibrium and moves at four metres per second. I can describe that instant with position and velocity. If I use the momentum instead of the velocity, how do I get back the same energy? I follow the calculation by hand and then have Mathematics Explorer compute the same state.

1. From the Session to the Legendre study

Open or create a Session in GX-TXT. In the main window, select Viewers and open the Mathematics tile. In the Mathematics Explorer window select Study. In the list of buttons on the tab look for Legendre transform at one state…, between Lagrangian action and residual… and Declare quadratic Lagrangian or Hamiltonian….

GX-TXT main window with an open Session, Viewers tab and Mathematics tile.
Step 1, entry. The active Session is shown at the top. The Mathematics tile is among the scientific viewers.
Full Mathematics Explorer window open on Study with the Legendre transform at one state button.
Step 1, choosing the study. In the full window look at the Study list on the right and the Legendre transform at one state… command.

2. Fill in a single state

In P012 the dialog of my test opened at 200 × 200 pixels. The headers were truncated and Evaluate state was out of view. Drag the bottom right corner to widen and heighten the dialog. In the test 930 × 745 pixels were enough to see fields, buttons and the result box.

The command opens a diagonal quadratic model already set up. For a mass and a spring one Cartesian coordinate is enough. Keep one row and fill in these fields, in the order in which they appear.

GUI fieldValueMeaning
Labelq1Name of the coordinate that reappears in the result.
q (m)1Position relative to equilibrium, in metres.
v (m/s)4Velocity along the coordinate, in metres per second.
m (kg)2Mass, positive, in kilograms.
k (N/m)3Spring stiffness, in newtons per metre.

To store the state after the calculation, set New Dataset ID to legendre_massamolla if free, and Dataset title to Stato massa e molla (“mass and spring state”).

3. Calculate by hand before reading the result

The kinetic energy is T = mv²/2 = 16 J and the elastic energy V = kq²/2 = 1.5 J. For the mass–spring model the Lagrangian is L(q,v) = T − V = 14.5 J at the assigned state. At fixed position the elastic term is constant with respect to v. Differentiating the kinetic term I get p = ∂L/∂v = mv = 8 kg·m/s.

With a positive mass I can invert p = mv and write v = p/m. In the transform pv − L I substitute this expression. The result depends only on position and momentum.

H(q,p) = pv − L = p²/(2m) + kq²/2 = 32 J − 14.5 J = 17.5 J.

4. Press Evaluate state and read the result

After Evaluate state wait for State evaluated. The first rows compare Hamiltonian H and Quadratic reference H. Both report 17.5 J. In row q1 read p = 8 kg·m/s and, in brackets, the reference m v = 8 kg·m/s. The next row repeats the inputs, useful to spot a swapped value.

The box shows the formula of L, together with the note on positive masses. The three separate values of T, V and L computed above come from the hand calculation. The viewer note says that Numeric uses the analytical derivative of the diagonal model. The quadratic reference is computed separately on the entered values. The GUI also reports the tolerances of the numerical comparison, 10−7 kg·m/s for the momentum or 10−6 J for the energy, plus 10−7 times the magnitude of the respective reference. Here the numbers shown coincide.

Evaluate state result with Hamiltonian H 17.5 J, reference 17.5 J and momentum 8 kg·m/s in row q1.
Step 4. Read H and its reference first, then p on row q1. The position, velocity, mass and stiffness values stay visible above and in the summary.

5. Store the state and reopen it from the catalogue

When the result is ready and the ID is free, Store state Dataset becomes enabled next to Evaluate state. Press it once and wait for completion. With legendre_massamolla the Job ended with outcome PASS and the Session kept the table.

Close the dialog and go back to the main window. Open the Dataset tab and, if the ID is missing from the list, use Refresh. Activate the legendre_massamolla Dataset with the indicator to the left of the ID, then press Open. Wait for loading and open Canonical table. In a single row you find q, v, m, k, the momentum and the Hamiltonian. The names momentum_1 and hamiltonian correspond to 8 and 17.5. The unit kg*m^2/s^2 is the joule and kg/s^2 is equivalent to N/m.

The result concerns a single state. To compare the energy at different instants you need a trajectory. Declaring a canonical Function follows the separate path Declare quadratic Lagrangian or Hamiltonian…. In P012 that path was blocked at Review Function in the diagnostic profile of the guide. Here the calculation starts from the five fields of the state dialog.

Screenshots of the Giux-Lab test on GX-TXT DEV112 P012, Mathematics Explorer 0.2.0. Independent check of the results (ZIP).

Back to the project Eight studies with Mathematics Explorer

Other steps of this project

Leave a Reply

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