Skip to content

fix the sign of Flight.potential_energy - #1204

Draft
Mohit-Ak wants to merge 1 commit into
RocketPy-Team:developfrom
Mohit-Ak:bug/potential-energy-sign
Draft

Mohit-Ak wants to merge 1 commit into
RocketPy-Team:developfrom
Mohit-Ak:bug/potential-energy-sign

Conversation

@Mohit-Ak

@Mohit-Ak Mohit-Ak commented Oct 8, 2026

Copy link
Copy Markdown

Pull request type

  • Code changes (bugfix, features)

Checklist

  • Tests for the changes have been added (if needed)
  • Lint (ruff check / ruff format --check) has passed locally
  • All tests (pytest tests/unit tests/integration) have passed locally

Current behavior

Flight.potential_energy computes mu * m * (1 / (z + R) - 1 / R), which is negative for z > 0 and gets more negative as the rocket climbs. Flight.total_energy inherits the sign error. Between burn out and apogee the mass is constant, so the change in potential energy should be m * g * dz; with the issue's script it comes out as -398754.6 J instead of +398711.0 J. The trajectory itself is not affected.

New behavior

The two terms are swapped, so the potential energy relative to sea level is positive and increases with altitude. Added test_potential_energy_increases_with_altitude, which checks that the burn-out-to-apogee change in potential_energy matches m * g * dz on the flight_calisto fixture. It fails on develop (-398045 J vs +398623 J) and passes with this change.

Breaking change

  • No

potential_energy and total_energy change sign (they were wrong before); the energy plots in Flight.plots and CompareFlights will now show the expected curves.

Fixes #1202

Flight.potential_energy computed mu * m * (1/(z + R) - 1/R), which is
negative for z > 0 and decreases as the rocket climbs. Swap the two terms
so the potential energy relative to sea level is positive and grows with
altitude. Flight.total_energy inherits the fix.

Fixes RocketPy-Team#1202
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant