Computational Physics Project in Python: Euler-Cromer Pendulum
Plan a computational physics project in Python: model a nonlinear pendulum with Euler-Cromer, run a convergence check, test energy and write up the results.
Professor Eric Editorial · Nov 29, 2026 · 7 min read
In this article
- What model are we simulating?
- What is the Euler-Cromer method?
- How do you check that the code is right?
- What did the convergence study show?
- Why not the plain Euler method?
- How do you structure the write-up?
- Which courses use this?
- What assignments does this help with, and what help is allowed?
- Computational project checklist
- Frequently asked questions
- Next step for your project
A computational physics project is a physics argument with a computer as the instrument. You write down a model, solve it numerically, test that the numbers are trustworthy and then use them to learn something. The test step is the one students skip, and it is the one graders look for.
What model are we simulating?
A simple pendulum of length L = 1.00 m, a point mass on a massless rigid rod, with a frictionless pivot and uniform gravity g = 9.80 m/s². The angle θ is measured from the downward vertical. Newton's second law for rotation gives the nonlinear equation
d²θ/dt² = −(g/L) sin θ
The usual textbook shortcut replaces sin θ by θ, which gives simple harmonic motion with period 2π√(L/g) = 2.007 s. We keep the sine. We release the pendulum from rest at θ₀ = 0.50 rad (28.6°). The exact period for that amplitude is T = 2π√(L/g) / AGM(1, cos(θ₀/2)), where AGM is the arithmetic-geometric mean. That gives T = 2.0389 s. A numerical integration of the exact period formula also gives 2.0389074 s. So the small-angle formula is about 1.6% too short here.
What is the Euler-Cromer method?
Write the second-order equation as two first-order ones, with ω = dθ/dt. A time step is dt. Then, in this order:
- Compute the new angular velocity: ω(new) = ω − (g/L) sin θ · dt.
- Compute the new angle using the new velocity: θ(new) = θ + ω(new) · dt.
- Advance the time by dt and repeat.
The ordinary Euler method uses the old ω in step 2. That small change makes Euler-Cromer a symplectic method, which keeps the energy from drifting in oscillatory problems. Both methods are first-order accurate in the state, but they behave very differently for oscillations, as the results below show.
How do you check that the code is right?
Use independent checks before you trust any result.
- Small-angle limit. Start from a tiny angle, such as 0.01 rad, and confirm the period approaches 2.007 s.
- Energy. Track the energy per unit m L², ε = ½ω² + (g/L)(1 − cos θ). It should stay nearly constant.
- Known answer. Compare with the exact period above.
- Symmetry. The motion from θ₀ and from −θ₀ should mirror each other.
What did the convergence study show?
For Euler-Cromer, the period error (simulated minus exact) at each time step was:
- dt = 0.02 s: T = 2.03862 s, error −2.9 × 10⁻⁴ s
- dt = 0.01 s: T = 2.03883 s, error −7.3 × 10⁻⁵ s
- dt = 0.005 s: error −1.8 × 10⁻⁵ s
- dt = 0.0025 s: error −4.6 × 10⁻⁶ s
- dt = 0.00125 s: error −1.1 × 10⁻⁶ s
Each time the step was halved, the error shrank by a factor of 4.00 (the printed ratios were 4.0006, 4.0022, 3.9998 and 3.9995). So for the period, the method behaves as second-order in dt even though the underlying update is first-order. That's an observed result for this quantity in this problem, and it shouldn't be generalized to every observable.
The energy tells a different story. The relative deviation of energy from its starting value stayed within bounds, and the bounds halved with the step: about −1.52% to +1.56% at dt = 0.01 s, −0.76% to +0.78% at 0.005 s, −0.38% to +0.39% at 0.0025 s and −0.19% to +0.19% at 0.00125 s. That is first-order behavior in the energy. And it didn't drift: a run of 120 s at dt = 0.01 s stayed within the same −1.52% to +1.56% band.
Why not the plain Euler method?
For comparison, the same pendulum was run with the plain Euler update. At dt = 0.01 s over 12 s, its energy rose by as much as 198% above the starting value. At dt = 0.0025 s it still rose by 32%, and over 120 s at dt = 0.01 s the energy increased by about 4,600%. The amplitude grows without bound, which is unphysical for a frictionless pendulum. This is the reason to use Euler-Cromer, or a higher-order method, for oscillators. It is also a good lesson for your report: show what happens with the naive method, because it demonstrates why your method matters.
How do you structure the write-up?
- Question. What are you computing, and why? For example: how much does a 0.50 rad amplitude lengthen the period?
- Model and assumptions. The equation, the parameters, the initial conditions and what you left out (air drag, pivot friction, a massive rod).
- Method. The update rules in words and equations, how the period was extracted and why.
- Validation. The small-angle limit, energy behavior and comparison with the exact period.
- Convergence. The step sizes, the errors and the ratio showing how error scales. Say what you observed, not what theory says should happen.
- Results and limitations. The period you found, with an error estimate from the convergence study. Say that the model ignores damping and so can't predict how real pendulums decay.
- Reproducibility. Library versions, parameters and a way to rerun. Your instructor may ask you to include the code, which should be your own and commented.
Plots should have labeled axes with units, and a convergence plot on logarithmic axes shows the slope of the error directly.
Which courses use this?
Computational projects appear in calculus-based introductory physics, computational physics courses, upper-division mechanics, engineering physics and graduate courses. In high school and AP courses, simulations are mostly used for exploration, and the AP exams don't require programming. AP is a trademark of the College Board, which isn't affiliated with Professor Eric. Introductory computational courses focus on Euler-Cromer and basic plotting, while upper-division courses add Runge-Kutta methods, adaptive steps and error analysis.
What assignments does this help with, and what help is allowed?
Computational work appears as lab-style projects, homework with code, capstone projects and research. Your code and results must be yours. Allowed help can include a worked example on a different system, feedback on your validation and convergence logic, tutoring on numerical methods and help structuring the write-up. Whether to use outside code or AI tools is set by your course policy, so check it.
Follow your school's honor code and your instructor's rules on outside help, and submit only your own work. We don't do graded online homework, quizzes, labs or exams. See our physics assignment help page.
Computational project checklist
Your checklist
0 of 7 done
Frequently asked questions
Why does Euler-Cromer conserve energy better than Euler?
It updates the velocity first and then uses the new velocity to move the position, which makes the step area-preserving in phase space. The energy then oscillates in a bounded band instead of growing.
How small should the time step be?
Small enough that the quantity you care about stops changing at the precision you need. A convergence study answers this for your problem: halve the step until the result changes by less than your target.
Is a convergence check the same as validating the physics?
No. Convergence shows the numbers settle to the solution of the equations. Validation checks that the equations match reality, for example by comparing with measured data.
Can I use a library instead of writing the update myself?
That depends on your course. Even if allowed, you still need to explain the method, test it and show convergence.
Next step for your project
Pick a different amplitude, predict the period from the small-angle formula and the amplitude correction, then run your own convergence study and compare. For feedback on your validation logic, a tutor or a worked example on a different system can help.