Skip to content

Add Classical and Quantum Hamiltonian functions to physics algorithms #13235

Closed

Description

@morgen-code

Feature description

I would like to suggest adding functions for the Hamiltonian in both classical mechanics and quantum mechanics
to the physics directory.

Proposed functions

  1. Classical Hamiltonian
    Computes H = T + V for a particle or system, where T is kinetic energy and V is potential energy.
    Example use case: free particle, harmonic oscillator, simple pendulum.

  2. Quantum Hamiltonian (1D)
    Constructs the Hamiltonian matrix for a particle in a 1D potential using finite difference discretization.
    Example use case: solving the time-independent Schrödinger equation.

Benefits

Provides a practical way for learners to understand and simulate physical systems in Python.
Fits the existing educational purpose of the physics directory as a collection of algorithmic implementations.

Activity

  1. devx099 commented on Oct 5, 2025

    @devx099

    Hello, I’m Dev
    I would like to work on this issue as part of Hacktoberfest. This would be my first open-source contribution.
    And I will really appreciate any advice or guidance you might have for me. or you can specify more if you can.
    Could you please assign this issue to me so I can start working on it?

  2. morgen-code commented on Oct 5, 2025

    @morgen-code
    Author

    Hi Dev (@devx099 )
    That’s great to hear. Thank you for your interest in working on this issue.

    Yes, please go ahead and start working on it.

    Here’s a suggested structure:

    • classical_hamiltonian(m, p, V) → returns p**2 / (2*m) + V
    • quantum_hamiltonian_1d(m, hbar, V, dx) → builds the Hamiltonian matrix using the finite difference method.
      • Note: hbar is included as an input parameter to allow flexible choice of unit systems (e.g., natural units or SI units).

    Let me know if you have any questions or would like feedback while implementing.
    I’ll be happy to help.

  3. pipineitor commented on Oct 6, 2025

    @pipineitor

    Hello, I’m Dev
    I would like to work on this issue as part of Hacktoberfest. This would be my first open-source contribution.
    And I will really appreciate any advice or guidance you might have for me. or you can specify more if you can.
    Could you please assign this issue to me so I can start working on it?

    My number is +58 4168068615 wsp

  4. cclauss commented on Sep 10, 2026

    @cclauss
    Member

    @priya-sundaram-dev, please review this issue with the pull request #15012

  5. priya-sundaram-dev commented on Sep 10, 2026

    @priya-sundaram-dev
    Contributor

    @cclauss reviewed #15012 — approved. Doctests verified by hand and the finite-difference quantum Hamiltonian is correct (tridiagonal, diagonal ħ²/(m·dx²)+V, off-diagonals -ħ²/(2m·dx²)); classical H=T+V checks out too. CI green. One optional nit noted (num_points duplicates len(potential)), non-blocking.

  6. added a commit that references this issue on Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis PR modified some existing files

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions