Special Relativity in Lagrangian Mechanics¶

da PowerShell -- jupyter nbconvert --to html notebook.ipynb

Geodetica¶

moto di una particella libera e di una particella carica in un campo elettromagnetico¶

Descrizione dell'esercizio¶

L'esercizio implementa, tramite codice Python, diversi concetti fondamentali della $\textbf{meccanica relativistica}$ e della $\textbf{dinamica lagrangiana}$, con particolare attenzione al moto di una particella libera e di una particella carica in un campo elettromagnetico.

Fattore di Lorentz¶

Dato un vettore velocità tridimensionale $\mathbf{v}$, viene calcolato il fattore di Lorentz $$\large \gamma = \frac{1}{\sqrt{1 - \frac{|\mathbf{v}|^2}{c^2}}} $$ dove $c$ è la velocità della luce nel vuoto. Questo fattore misura gli effetti relativistici dovuti ad alte velocità.

Lagrangiana relativistica di una particella libera¶

Per una particella libera di massa $m$, la lagrangiana relativistica è definita come $$\large \mathcal{L} = - m c^2 \sqrt{1 - \frac{|\mathbf{v}|^2}{c^2}} . $$ Essa sostituisce la lagrangiana classica $T - V$ ed è invariante per trasformazioni di Lorentz.

Equazioni di Eulero--Lagrange¶

A partire dalla lagrangiana relativistica, il codice calcola il $\textbf{momento generalizzato}$ $$\large \mathbf{p} = \frac{\partial \mathcal{L}}{\partial \mathbf{v}} = \gamma m \mathbf{v}, $$ che coincide con il momento relativistico. Poiché la particella è libera, la forza generalizzata risulta nulla: $$\large \mathbf{F} = \frac{d\mathbf{p}}{dt} = \mathbf{0}. $$

Quadrimpulso¶

Il quadrimpulso relativistico è definito come $$\large p^\mu = \left( \frac{E}{c}, \mathbf{p} \right) = \left( \frac{\gamma m c^2}{c}, \gamma m v_x, \gamma m v_y, \gamma m v_z \right) = \left( \gamma m c, \gamma m v_x, \gamma m v_y, \gamma m v_z \right), $$ dove l'energia totale relativistica è $$\large E = \gamma m c^2. $$ Il codice restituisce il quadrivettore energia--impulso in forma esplicita.

----------------------------------------------------------------------------------¶

Il quadrimpulso relativistico di una particella di massa $m$ che si muove con velocità $\mathbf{v} = (v_x, v_y, v_z)$ è definito come $$\large \mathbf{p} = \left( \frac{E}{c}, p_x, p_y, p_z \right), $$ dove l'energia relativistica totale è $$\large E = \gamma m c^2, \qquad \gamma = \frac{1}{\sqrt{1 - \frac{v_x^2 + v_y^2 + v_z^2}{c^2}}}. $$

Le componenti spaziali del quadrimpulso coincidono con il momento relativistico: $$\large \begin{aligned} p_x &= \gamma m v_x, \\ p_y &= \gamma m v_y, \\ p_z &= \gamma m v_z. \end{aligned} $$

In forma completamente sviluppata, il quadrimpulso risulta quindi $$\large \mathbf{p} = \left( \frac{\gamma m c^2}{c}, \gamma m v_x, \gamma m v_y, \gamma m v_z \right) = \left( \gamma m c, \gamma m v_x, \gamma m v_y, \gamma m v_z \right). $$

-----------------------------------------------------------------------------¶

Particella carica in un campo elettromagnetico¶

Per una particella di carica $q$ immersa in un campo elettromagnetico, la lagrangiana diventa $$\large \mathcal{L} m c^2 \sqrt{1 - \frac{|\mathbf{v}|^2}{c^2}}q \left( \mathbf{v} \cdot \mathbf{A} - \phi \right),$$ dove $\mathbf{A}$ è il potenziale vettore e $\phi$ il potenziale scalare.

### Forza di Lorentz relativistica

Infine, il codice implementa l'equazione della forza di Lorentz nella forma relativistica: $$\large \mathbf{F} = q \left( \mathbf{E}\mathbf{v} \times \mathbf{B}\frac{\mathbf{v} (\mathbf{v} \cdot \mathbf{E})}{c^2}\right), $$ che descrive il moto di una particella carica in presenza di campi elettrici e magnetici.

Conclusione¶

L'esercizio mostra come concetti teorici della relatività ristretta e della meccanica analitica possano essere tradotti in codice numerico, mettendo in evidenza il legame tra lagrangiana, momento relativistico, quadrimpulso e forza di Lorentz.

In [ ]:
import numpy as np 

def lorentz_factor(v, c=299792458):
    """
    Calculate the Lorentz factor.
        :param v: Velocity.
        :param c: Speed of light.
    :retum: 
        Lorentz factor.
    """
    v2 = np.dot(v, v)
    return 1.0 / np.sqrt(1 - v2 / c**2)

def relativistic_lagrangian(v, m, c=299792458):
    """
    Calculate the relativistic Lagrangian for a free particle.
        :param v: Velocity of the particle.
        :param m: Mass of the particle.
        :param c: Speed of light.
    :return: 
        Lagrangian value.
    """
    v2 = np.dot(v, v)
    return -m * c**2 * np.sqrt(1 - v2 / c**2)
    
def euler_lagrange_equations(lagrangian, x, v, m):
    """
    Calculate the Euler-Lagrange equation result for a given
    lagrangian.
        :param lagrangian: Lagrangian function.
        :param x: Position.
        :param v: Velocity.
    :return: 
        Generalized momentum and resulting force.
    """
    # Assuming x and v are numpy arrays
    gamma = lorentz_factor(v)
    p = gamma * m * v          # momento relativistico
    force = np.zeros_like(v)  # nessuna forza (particella libera)
    return p, force

def four_momentum(v, m, c=299792458):
    """
    Calculate the four-momentum of a particle.
        :param v: Velocity of the particle.
        :param m: Mass of the particle.
        :param c: Speed of light.
    :retum: 
        Four-momentum vector.
    """
    gamma = lorentz_factor(v, c)
    E = gamma * m * c**2
    p = gamma * m * v
    return np.array([E / c, *p])

def lagrangian_in_em_field(v, m, q, A, phi, c=299792458):
    """
    Calculate the Lagrangian for a charged particle in an
    electromagnetic field.
        :param v: Velocity of the particle.
        :param m: Mass of the particle.
        :param q: Charge of the particle.
        :param A: Vector potential.
        :param phi: Scalar potential.
        :param c: Speed of light.
    :return: 
        Lagrangian value.
    """
    return relativistic_lagrangian(v, m, c) + q * (np.dot(v, A) - phi)

def lorentz_force_eq(v, q, E, B, c=299792458):
    """
    Calculate the Lorentz force equation for a charged particle.
        :param v: Velocity of the particle.
        :param q: Charge of the particle. 
        :param E: Electric field.
        :param B: Magnetic field.
    :return: 
        Force vector.
    """
    gamma = lorentz_factor(v, c)
    v_dot_E = np.dot(v, E)
    return q * (E + np.cross(v, B) - v * v_dot_E / c**2)

def relativistic_momentum(v, m, c=299792458):
    gamma = lorentz_factor(v, c)
    return gamma * m * v

# Demonstration inputs
velocity = np.array([1e7, 0, 0]) # Example velocity in m/s
mass = 1.0 # Example mass in kg
charge = 1.6e-19 # Charge of particle in C
A = np.array([0, 0, 0])
phi = 0
vector_potential = np.array([0, 0, 0]) # Example vector potential
scalar_potential = 0 # Example scalar potential
E_field = np.array([0, 0, 0]) # Example electric field
B_field = np.array([0, 0, 1e-6]) # Example magnetic field
lagrangian_value = relativistic_lagrangian(velocity, mass)
p, el_result = euler_lagrange_equations(lambda v: relativistic_lagrangian(v, mass), np.array([0, 0, 0]), velocity, mass)
four_m_momentum = four_momentum (velocity, mass)
lagrange_em = lagrangian_in_em_field(velocity, mass, charge, vector_potential, scalar_potential)
force = lorentz_force_eq(velocity, charge, E_field, B_field)

F = lorentz_force_eq(velocity, charge, E_field, B_field)
print("Lagrangian:", lagrangian_value)
print("Generalized Momentum:", p)
print("Euler-Lagrange Result:", el_result)
print("Four-Momentum:", four_m_momentum)
print("Lagrangian in EM Field:", lagrange_em)
print("Lorentz Force:", force)
print('')

L_free = relativistic_lagrangian(velocity, mass)
p = relativistic_momentum(velocity, mass)
p4 = four_momentum(velocity, mass)
L_em = lagrangian_in_em_field(velocity, mass, charge, A, phi)
"""
print("Lagrangian:", lagrangian_value)
print("Generalized Momentum:", p)
print("Four-Momentum:", four_m_momentum)
print("Lagrangian in EM Field:", lagrange_em)
"""
a=1

Geodetica con grafico¶

Perfetto. Facciamo integrazione numerica della traiettoria relativistica in modo fisicamente corretto, senza scorciatoie newtoniane. Useremo: equazione fondamentale $\frac{d}{dt}(\gamma mv)=F$

  • forza di Lorentz relativistica
  • integrazione RK4 (stabile e chiara)
  • stato dinamico: posizione + velocità

Equazioni del moto da integrare Scriviamo il sistema in forma esplicita: Stato $y=(x,v)$ Dinamica \begin{cases} x˙=v \\ v˙=\frac{1}{\gamma m} \left[ F−\frac{v}{c^2}(v\cdot F) \right] \end{cases}

  • Questa è la vera accelerazione relativistica.
In [9]:
import numpy as np 

def lorentz_factor(v, c=299792458):
    """
    Calculate the Lorentz factor.
        :param v: Velocity.
        :param c: Speed of light.
    :retum: 
        Lorentz factor.
    """
    v2 = np.dot(v, v)
    return 1.0 / np.sqrt(1 - v2 / c**2)

def relativistic_acceleration(v, F, m, c=299792458):
    gamma = lorentz_factor(v, c)
    v_dot_F = np.dot(v, F)
    return (F - v * v_dot_F / c**2) / (gamma * m)

def lorentz_force(v, q, E, B):
    return q * (E + np.cross(v, B))

def equations_of_motion(state, q, m, E, B, c=299792458):
    x = state[:3]
    p = state[3:]

    gamma = np.sqrt(1 + np.dot(p, p) / (m*m*c*c))
    v = p / (gamma * m)

    dxdt = v
    dpdt = q * (E + np.cross(v, B))

    return np.concatenate([dxdt, dpdt])

def rk4_step(f, y, dt, *args):
    k1 = f(y, *args)
    k2 = f(y + 0.5 * dt * k1, *args)
    k3 = f(y + 0.5 * dt * k2, *args)
    k4 = f(y + dt * k3, *args)
    return y + (dt / 6.0) * (k1 + 2*k2 + 2*k3 + k4)

def integrate_trajectory(state0, q, m, E, B, dt, steps):
    state = state0.copy()
    trajectory = np.zeros((steps, 3))

    for i in range(steps):
        trajectory[i] = state[:3]
        state = rk4_step(equations_of_motion, state, dt, q, m, E, B)
    return trajectory

# Parametri
q = -1.6e-19   # C
m = 9.11e-31      # kg
B = np.array([0, 0, 1e-3])
E = np.array([0, 0, 0])

x0 = np.array([0.0, 0.0, 0.0])
v0 = np.array([1e7, 0.0, 3e7])   # <-- aggiunta componente z

gamma0 = lorentz_factor(v0)
p0 = gamma0 * m * v0

state0 = np.concatenate([x0, p0])

dt = 1e-11
steps = 10000

traj = integrate_trajectory(state0, q, m, E, B, dt, steps)

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D  # necessario anche se non usato direttamente

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(traj[:, 0], traj[:, 1], traj[:, 2])
ax.set_xlabel('x [m]')
ax.set_ylabel('y [m]')
ax.set_zlabel('z [m]')
ax.set_title('Traiettoria 3D (elica)')
plt.tight_layout()
plt.show()
No description has been provided for this image

Orbita di Mercurio - senza usare il tensore metrico - Geodetica¶

aggiungendo al potenziale newtoniano una correzione relativistica efficace¶

$$\large V(r) = - \frac{G M m}{r} + \begin{array}{c} \frac{L^2}{2 m r^2} \\ \text{termine centrifugo} \end{array} - \begin{array}{c} \frac{G M L^2}{m c^2 r^3} \\ \text{correzione GR} \end{array} $$
In [16]:
import numpy as np 

def lorentz_factor(v, c=299792458):
    """
    Calculate the Lorentz factor.
        :param v: Velocity.
        :param c: Speed of light.
    :retum: 
        Lorentz factor.
    """
    v2 = np.dot(v, v)
    return 1.0 / np.sqrt(1 - v2 / c**2)

def relativistic_acceleration(v, F, m, c=299792458):
    gamma = lorentz_factor(v, c)
    v_dot_F = np.dot(v, F)
    return (F - v * v_dot_F / c**2) / (gamma * m)

def lorentz_force(v, q, E, B):
    return q * (E + np.cross(v, B))

def equations_of_motion(state, GM, c):
    r = state[:3]
    v = state[3:]

    r_norm = np.linalg.norm(r)
    r_hat = r / r_norm

    # momento angolare specifico
    L = np.linalg.norm(np.cross(r, v))

    # accelerazione newtoniana
    a_newton = -GM / r_norm**2 * r_hat

    # correzione relativistica (1PN)
    #a_gr = -3 * GM * L**2 / (c**2 * r_norm**4) * r_hat
    # coeff. amplificato per visualizzazione didattica
    a_gr = -1e6 * 3 * GM * L**2 / (c**2 * r_norm**4) * r_hat


    a = a_newton + a_gr

    return np.concatenate([v, a])

def rk4_step(f, y, dt, *args):
    k1 = f(y, *args)
    k2 = f(y + 0.5 * dt * k1, *args)
    k3 = f(y + 0.5 * dt * k2, *args)
    k4 = f(y + dt * k3, *args)
    return y + (dt / 6.0) * (k1 + 2*k2 + 2*k3 + k4)

def integrate_trajectory(state0, GM, c, dt, steps):
    state = state0.copy()
    traj = np.zeros((steps, 3))

    for i in range(steps):
        traj[i] = state[:3]
        state = rk4_step(equations_of_motion, state, dt, GM, c)

    return traj

G  = 6.67430e-11
M  = 1.989e30          # Sole
GM = G * M
c  = 3e8

# Mercurio
a = 5.79e10            # semiasse maggiore [m]
e = 0.2056

# condizioni iniziali (perielio)
r0 = np.array([a*(1-e), 0.0, 0.0])
v0 = np.array([0.0,
               np.sqrt(GM*(1+e)/(a*(1-e))),
               0.0])

state0 = np.concatenate([r0, v0])

dt = 1000        # ~ 17 minuti
steps = 20000   # ~ molte orbite

traj = integrate_trajectory(state0, GM, c, dt, steps)

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D  # necessario anche se non usato direttamente

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

ax.plot(traj[:, 0], traj[:, 1], traj[:, 2])

ax.set_xlabel('x [m]')
ax.set_ylabel('y [m]')
ax.set_zlabel('z [m]')

ax.set_title('Precessione di Mercurio')

plt.tight_layout()
plt.show()
No description has been provided for this image
In [ ]: